Skip to content

Commit 0225e64

Browse files
committed
Update member name regexp to support UTF8 alphabetic and numeric characters
see: https://ruby-doc.org/3.0.6/Regexp.html#class-Regexp-label-Character+Properties
1 parent 4e31ac9 commit 0225e64

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/jsonpath.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def initialize(path, opts = {})
3030
until scanner.eos?
3131
if (token = scanner.scan(/\$\B|@\B|\*|\.\./))
3232
@path << token
33-
elsif (token = scanner.scan(/[$@a-zA-Z0-9:{}_-]+/))
33+
elsif (token = scanner.scan(/[$@\p{Alnum}:{}_-]+/))
3434
@path << "['#{token}']"
3535
elsif (token = scanner.scan(/'(.*?)'/))
3636
@path << "[#{token}]"
@@ -85,7 +85,7 @@ def on(obj_or_str, opts = {})
8585
end
8686
a
8787
end
88-
88+
8989
def self.fetch_all_path(obj)
9090
all_paths = ['$']
9191
find_path(obj, '$', all_paths, obj.class == Array)

test/test_jsonpath.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def test_use_first
245245
end
246246

247247
def test_counting
248-
assert_equal 57, JsonPath.new('$..*').on(@object).to_a.size
248+
assert_equal 58, JsonPath.new('$..*').on(@object).to_a.size
249249
end
250250

251251
def test_space_in_path
@@ -475,6 +475,11 @@ def test_support_underscore_in_member_names
475475
JsonPath.new('$.store._links').on(@object)
476476
end
477477

478+
def test_support_for_umlauts_in_member_names
479+
assert_equal [@object['store']['Übermorgen']],
480+
JsonPath.new('$.store.Übermorgen').on(@object)
481+
end
482+
478483
def test_dig_return_string
479484
assert_equal ['asdf'], JsonPath.new("$.store.book..tags[?(@ == 'asdf')]").on(@object)
480485
assert_equal [], JsonPath.new("$.store.book..tags[?(@ == 'not_asdf')]").on(@object)
@@ -1246,10 +1251,11 @@ def example_object
12461251
},
12471252
'@id' => 'http://example.org/store/42',
12481253
'$meta-data' => 'whatevs',
1254+
'Übermorgen' => 'The day after tomorrow',
12491255
'_links' => { 'self' => {} }
12501256
} }
12511257
end
1252-
1258+
12531259
def test_fetch_all_path
12541260
data = {
12551261
"foo" => nil,

0 commit comments

Comments
 (0)