You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ParserError#json_path raises NoMethodError when parsing with symbolize_names: true #1117
Since 3.1.0, calling json_path on a JSON::ParserError raised while parsing with symbolize_names: true raises NoMethodError as soon as the path contains an object key:
require"json"beginJSON.parse('{"a": [1, {"b": xyz}]}',symbolize_names: true)rescueJSON::ParserError=>errorerror.json_pathend# => undefined method 'valid_encoding?' for an instance of Symbol (NoMethodError)
Duplicate key errors in nested objects are affected the same way:
error.json_path should return "$.a[1].b" (and "$.x.a" for the second example), as it does without symbolize_names.
Root cause
With symbolize_names: true the keys collected for the path are Symbols. ParserError#build_json_path accepts String and Symbol segments, but the check added in "Handle invalid encoding in JSON path keys" (#1113) calls segment.valid_encoding?, which only exists on String. Converting the segment with to_s before the checks fixes it.
Activity