Skip to content
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
merged 3 commits into from
Mar 21, 2024

Conversation

nattsw
Copy link
Contributor

@nattsw nattsw commented Mar 21, 2024

Currently, in a user json with false values, due to a || operator, the value incorrectly evaluates to the right hand side. This was causing an issue.

e.g.

deref = fragment[first_seg] || fragment[first_seg.to_sym]

This PR fixes that and appropriately assigns false to the specified path for user details.

@@ -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
Contributor Author

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

nattsw and others added 2 commits March 21, 2024 17:34
Co-authored-by: Jarek Radosz <jradosz@gmail.com>
Co-authored-by: Jarek Radosz <jradosz@gmail.com>
@nattsw nattsw merged commit f11229a into main Mar 21, 2024
@nattsw nattsw deleted the assign-false-correctly branch March 21, 2024 09:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants