jsonpath 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -7
- data/jsonpath.gemspec +1 -9
- data/lib/jsonpath/parser.rb +37 -8
- data/lib/jsonpath/version.rb +1 -1
- data/test/test_jsonpath.rb +1 -1
- metadata +14 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c156dcfda0e97156b872e63c64fc1b4a4f2379f217103165f22de78e3415800
|
4
|
+
data.tar.gz: ab9647efecba7fa057dc77b4f447c9ea09aba719d117e95edefeace45915c2cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74ca2152d154f76497df525616aba1792c192be58025c47e6e76a9ebb6c6ebd3a3cbbcf66c2a7b49d4ec1d211ce46ce0b2ba3c334b6c755e0acde4042be9f27f
|
7
|
+
data.tar.gz: 47d2c181d409d1091b23080e8f62f8b708e5bd171040599b2ed3f1ce3c0a379e5a11eb72b441c61395682ec40f1f6d16bdfb51fa967a4a16046ba63caefb99ca
|
data/.travis.yml
CHANGED
data/jsonpath.gemspec
CHANGED
@@ -5,10 +5,7 @@ require File.join(File.dirname(__FILE__), 'lib', 'jsonpath', 'version')
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'jsonpath'
|
7
7
|
s.version = JsonPath::VERSION
|
8
|
-
|
9
|
-
s.required_rubygems_version =
|
10
|
-
Gem::Requirement.new('>= 0')
|
11
|
-
end
|
8
|
+
s.required_ruby_version = '>= 2.5'
|
12
9
|
s.authors = ['Joshua Hull', 'Gergely Brautigam']
|
13
10
|
s.summary = 'Ruby implementation of http://goessner.net/articles/JsonPath/'
|
14
11
|
s.description = 'Ruby implementation of http://goessner.net/articles/JsonPath/.'
|
@@ -16,17 +13,12 @@ Gem::Specification.new do |s|
|
|
16
13
|
s.extra_rdoc_files = ['README.md']
|
17
14
|
s.files = `git ls-files`.split("\n")
|
18
15
|
s.homepage = 'https://github.com/joshbuddy/jsonpath'
|
19
|
-
s.rdoc_options = ['--charset=UTF-8']
|
20
|
-
s.require_paths = ['lib']
|
21
|
-
s.rubygems_version = '1.3.7'
|
22
16
|
s.test_files = `git ls-files`.split("\n").select { |f| f =~ /^spec/ }
|
23
|
-
s.rubyforge_project = 'jsonpath'
|
24
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
25
18
|
s.licenses = ['MIT']
|
26
19
|
|
27
20
|
# dependencies
|
28
21
|
s.add_runtime_dependency 'multi_json'
|
29
|
-
s.add_runtime_dependency 'to_regexp', '~> 0.2.1'
|
30
22
|
s.add_development_dependency 'bundler'
|
31
23
|
s.add_development_dependency 'code_stats'
|
32
24
|
s.add_development_dependency 'minitest', '~> 2.2.0'
|
data/lib/jsonpath/parser.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'strscan'
|
4
|
-
require 'to_regexp'
|
5
4
|
|
6
5
|
class JsonPath
|
7
6
|
# Parser parses and evaluates an expression passed to @_current_node.
|
8
7
|
class Parser
|
8
|
+
REGEX = /\A\/(.+)\/([imxnesu]*)\z|\A%r{(.+)}([imxnesu]*)\z/
|
9
|
+
|
9
10
|
def initialize(node)
|
10
11
|
@_current_node = node
|
11
12
|
@_expr_map = {}
|
@@ -71,13 +72,16 @@ class JsonPath
|
|
71
72
|
elsif (t = scanner.scan(/(\s+)?'?.*'?(\s+)?/))
|
72
73
|
# If we encounter a node which does not contain `'` it means
|
73
74
|
# that we are dealing with a boolean type.
|
74
|
-
operand =
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
75
|
+
operand =
|
76
|
+
if t == 'true'
|
77
|
+
true
|
78
|
+
elsif t == 'false'
|
79
|
+
false
|
80
|
+
elsif operator.to_s.strip == '=~'
|
81
|
+
parse_regex(t)
|
82
|
+
else
|
83
|
+
t.gsub(%r{^'|'$}, '').strip
|
84
|
+
end
|
81
85
|
elsif (t = scanner.scan(/\/\w+\//))
|
82
86
|
elsif (t = scanner.scan(/.*/))
|
83
87
|
raise "Could not process symbol: #{t}"
|
@@ -102,6 +106,31 @@ class JsonPath
|
|
102
106
|
|
103
107
|
private
|
104
108
|
|
109
|
+
# /foo/i -> Regex.new("foo", Regexp::IGNORECASE) without using eval
|
110
|
+
# also supports %r{foo}i
|
111
|
+
# following https://github.com/seamusabshere/to_regexp/blob/master/lib/to_regexp.rb
|
112
|
+
def parse_regex(t)
|
113
|
+
t =~ REGEX
|
114
|
+
content = $1 || $3
|
115
|
+
options = $2 || $4
|
116
|
+
|
117
|
+
raise "unsupported regex #{t} use /foo/ style" if !content || !options
|
118
|
+
|
119
|
+
content = content.gsub '\\/', '/'
|
120
|
+
|
121
|
+
flags = 0
|
122
|
+
flags |= Regexp::IGNORECASE if options.include?('i')
|
123
|
+
flags |= Regexp::MULTILINE if options.include?('m')
|
124
|
+
flags |= Regexp::EXTENDED if options.include?('x')
|
125
|
+
|
126
|
+
# 'n' = none, 'e' = EUC, 's' = SJIS, 'u' = UTF-8
|
127
|
+
lang = options.scan(/[nes]/).join.downcase # ignores u since that is default and causes a warning
|
128
|
+
|
129
|
+
args = [content, flags]
|
130
|
+
args << lang unless lang.empty? # avoid warning
|
131
|
+
Regexp.new(*args)
|
132
|
+
end
|
133
|
+
|
105
134
|
# This will break down a parenthesis from the left to the right
|
106
135
|
# and replace the given expression with it's returned value.
|
107
136
|
# It does this in order to make it easy to eliminate groups
|
data/lib/jsonpath/version.rb
CHANGED
data/test/test_jsonpath.rb
CHANGED
@@ -748,7 +748,7 @@ class TestJsonpath < MiniTest::Unit::TestCase
|
|
748
748
|
end
|
749
749
|
|
750
750
|
def test_runtime_error_frozen_string
|
751
|
-
skip('in ruby version below 2.2.0 this error is not raised') if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.0')
|
751
|
+
skip('in ruby version below 2.2.0 this error is not raised') if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.0') || Gem::Version.new(RUBY_VERSION) > Gem::Version::new('2.6')
|
752
752
|
json = '
|
753
753
|
{
|
754
754
|
"test": "something"
|
metadata
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonpath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Hull
|
8
8
|
- Gergely Brautigam
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-11-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name: multi_json
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
16
|
requirements:
|
18
17
|
- - ">="
|
19
18
|
- !ruby/object:Gem::Version
|
20
19
|
version: '0'
|
20
|
+
name: multi_json
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,26 +26,12 @@ dependencies:
|
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
|
-
name: to_regexp
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - "~>"
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: 0.2.1
|
35
|
-
type: :runtime
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - "~>"
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: 0.2.1
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: bundler
|
44
29
|
requirement: !ruby/object:Gem::Requirement
|
45
30
|
requirements:
|
46
31
|
- - ">="
|
47
32
|
- !ruby/object:Gem::Version
|
48
33
|
version: '0'
|
34
|
+
name: bundler
|
49
35
|
type: :development
|
50
36
|
prerelease: false
|
51
37
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -54,12 +40,12 @@ dependencies:
|
|
54
40
|
- !ruby/object:Gem::Version
|
55
41
|
version: '0'
|
56
42
|
- !ruby/object:Gem::Dependency
|
57
|
-
name: code_stats
|
58
43
|
requirement: !ruby/object:Gem::Requirement
|
59
44
|
requirements:
|
60
45
|
- - ">="
|
61
46
|
- !ruby/object:Gem::Version
|
62
47
|
version: '0'
|
48
|
+
name: code_stats
|
63
49
|
type: :development
|
64
50
|
prerelease: false
|
65
51
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -68,12 +54,12 @@ dependencies:
|
|
68
54
|
- !ruby/object:Gem::Version
|
69
55
|
version: '0'
|
70
56
|
- !ruby/object:Gem::Dependency
|
71
|
-
name: minitest
|
72
57
|
requirement: !ruby/object:Gem::Requirement
|
73
58
|
requirements:
|
74
59
|
- - "~>"
|
75
60
|
- !ruby/object:Gem::Version
|
76
61
|
version: 2.2.0
|
62
|
+
name: minitest
|
77
63
|
type: :development
|
78
64
|
prerelease: false
|
79
65
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -82,12 +68,12 @@ dependencies:
|
|
82
68
|
- !ruby/object:Gem::Version
|
83
69
|
version: 2.2.0
|
84
70
|
- !ruby/object:Gem::Dependency
|
85
|
-
name: phocus
|
86
71
|
requirement: !ruby/object:Gem::Requirement
|
87
72
|
requirements:
|
88
73
|
- - ">="
|
89
74
|
- !ruby/object:Gem::Version
|
90
75
|
version: '0'
|
76
|
+
name: phocus
|
91
77
|
type: :development
|
92
78
|
prerelease: false
|
93
79
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -96,12 +82,12 @@ dependencies:
|
|
96
82
|
- !ruby/object:Gem::Version
|
97
83
|
version: '0'
|
98
84
|
- !ruby/object:Gem::Dependency
|
99
|
-
name: rake
|
100
85
|
requirement: !ruby/object:Gem::Requirement
|
101
86
|
requirements:
|
102
87
|
- - ">="
|
103
88
|
- !ruby/object:Gem::Version
|
104
89
|
version: '0'
|
90
|
+
name: rake
|
105
91
|
type: :development
|
106
92
|
prerelease: false
|
107
93
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -142,24 +128,23 @@ homepage: https://github.com/joshbuddy/jsonpath
|
|
142
128
|
licenses:
|
143
129
|
- MIT
|
144
130
|
metadata: {}
|
145
|
-
post_install_message:
|
146
|
-
rdoc_options:
|
147
|
-
- "--charset=UTF-8"
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
148
133
|
require_paths:
|
149
134
|
- lib
|
150
135
|
required_ruby_version: !ruby/object:Gem::Requirement
|
151
136
|
requirements:
|
152
137
|
- - ">="
|
153
138
|
- !ruby/object:Gem::Version
|
154
|
-
version: '
|
139
|
+
version: '2.5'
|
155
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
141
|
requirements:
|
157
142
|
- - ">="
|
158
143
|
- !ruby/object:Gem::Version
|
159
144
|
version: '0'
|
160
145
|
requirements: []
|
161
|
-
rubygems_version: 3.0.
|
162
|
-
signing_key:
|
146
|
+
rubygems_version: 3.0.8
|
147
|
+
signing_key:
|
163
148
|
specification_version: 4
|
164
149
|
summary: Ruby implementation of http://goessner.net/articles/JsonPath/
|
165
150
|
test_files: []
|