Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 14, 2025. It is now read-only.

FIX: Appropriately assign values when fetching user details#100

Merged
nattsw merged 3 commits intomainfromassign-false-correctly
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletionslib/oauth2_basic_authenticator.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -84,7 +84,7 @@ def walk_path(fragment, segments, seg_index = 0)
return nil unless fragment.is_a?(Hash) || fragment.is_a?(Array)
first_seg = segments[seg_index].scan(/([\d+])/).length > 0 ? first_seg.split("[")[0] : first_seg
if fragment.is_a?(Hash)
deref = fragment[first_seg] || fragment[first_seg.to_sym]
deref = fragment[first_seg]
else
array_index = 0
if (seg_index > 0)
Expand All@@ -98,7 +98,7 @@ def walk_path(fragment, segments, seg_index = 0)
end
end

if(deref.blank? || seg_index == segments.size - 1)
if deref.blank? || seg_index == segments.size - 1
deref
else
seg_index += 1
Expand All@@ -113,7 +113,8 @@ def json_walk(result, user_json, prop, custom_path: nil)
path = path.gsub(".[].", ".").gsub(".[", "[")
segments = parse_segments(path)
val = walk_path(user_json, segments)
result[prop] = val if val.present?
# [] should be nil, false should be false
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

There's already a test for the []->nil
it "can walk json and handle an empty array" do

result[prop] = val.presence || (val == [] ? nil : val)
end
end

Expand Down
15 changes: 15 additions & 0 deletionsspec/plugin_spec.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -312,6 +312,21 @@
expect(result).to eq "http://example.com/1.png"
end

it "can walk json and appropriately assign a `false`" do
authenticator = OAuth2BasicAuthenticator.new
json_string = '{"user":{"id":1234, "data": {"address":"test@example.com", "is_cat": false}}}'
SiteSetting.oauth2_json_email_verified_path = "user.data.is_cat"
result =
authenticator.json_walk(
{},
JSON.parse(json_string),
"extra:user.data.is_cat",
custom_path: "user.data.is_cat",
)

expect(result).to eq false
end

describe "token_callback" do
let(:user) { Fabricate(:user) }
let(:strategy) { OmniAuth::Strategies::Oauth2Basic.new({}) }
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp