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.

Commitf11229a

Browse files
authored
FIX: Appropriately assign values when fetching user details (#100)
FIX: Appropriately assign values when fetching user details
1 parent5cd7a79 commitf11229a

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

‎lib/oauth2_basic_authenticator.rb‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def walk_path(fragment, segments, seg_index = 0)
8484
returnnilunlessfragment.is_a?(Hash) ||fragment.is_a?(Array)
8585
first_seg=segments[seg_index].scan(/([\d+])/).length >0 ?first_seg.split("[")[0] :first_seg
8686
iffragment.is_a?(Hash)
87-
deref=fragment[first_seg] ||fragment[first_seg.to_sym]
87+
deref=fragment[first_seg]
8888
else
8989
array_index=0
9090
if(seg_index >0)
@@ -98,7 +98,7 @@ def walk_path(fragment, segments, seg_index = 0)
9898
end
9999
end
100100

101-
if(deref.blank? ||seg_index ==segments.size -1)
101+
ifderef.blank? ||seg_index ==segments.size -1
102102
deref
103103
else
104104
seg_index +=1
@@ -113,7 +113,8 @@ def json_walk(result, user_json, prop, custom_path: nil)
113113
path=path.gsub(".[].",".").gsub(".[","[")
114114
segments=parse_segments(path)
115115
val=walk_path(user_json,segments)
116-
result[prop]=valifval.present?
116+
# [] should be nil, false should be false
117+
result[prop]=val.presence ||(val ==[] ?nil :val)
117118
end
118119
end
119120

‎spec/plugin_spec.rb‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,21 @@
312312
expect(result).toeq"http://example.com/1.png"
313313
end
314314

315+
it"can walk json and appropriately assign a `false`"do
316+
authenticator=OAuth2BasicAuthenticator.new
317+
json_string='{"user":{"id":1234, "data": {"address":"test@example.com", "is_cat": false}}}'
318+
SiteSetting.oauth2_json_email_verified_path="user.data.is_cat"
319+
result=
320+
authenticator.json_walk(
321+
{},
322+
JSON.parse(json_string),
323+
"extra:user.data.is_cat",
324+
custom_path:"user.data.is_cat",
325+
)
326+
327+
expect(result).toeqfalse
328+
end
329+
315330
describe"token_callback"do
316331
let(:user){Fabricate(:user)}
317332
let(:strategy){OmniAuth::Strategies::Oauth2Basic.new({})}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp