re2 2.4.3 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/Gemfile +2 -0
- data/README.md +281 -192
- data/Rakefile +1 -1
- data/dependencies.yml +4 -4
- data/ext/re2/extconf.rb +250 -358
- data/ext/re2/re2.cc +505 -284
- data/ext/re2/recipes.rb +31 -20
- data/lib/re2/regexp.rb +72 -0
- data/lib/re2/scanner.rb +11 -0
- data/lib/re2/string.rb +12 -59
- data/lib/re2/version.rb +10 -1
- data/lib/re2.rb +9 -3
- data/ports/archives/20240116.1.tar.gz +0 -0
- data/ports/archives/re2-2024-04-01.tar.gz +0 -0
- data/re2.gemspec +5 -2
- data/spec/kernel_spec.rb +10 -2
- data/spec/re2/match_data_spec.rb +98 -28
- data/spec/re2/regexp_spec.rb +546 -113
- data/spec/re2/scanner_spec.rb +26 -9
- data/spec/re2/set_spec.rb +28 -18
- data/spec/re2/string_spec.rb +2 -0
- data/spec/re2_spec.rb +34 -4
- data/spec/spec_helper.rb +2 -0
- metadata +10 -9
- data/ports/archives/20230802.1.tar.gz +0 -0
- data/ports/archives/re2-2023-11-01.tar.gz +0 -0
data/spec/re2/scanner_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RSpec.describe RE2::Scanner do
|
4
4
|
describe "#regexp" do
|
@@ -34,6 +34,16 @@ RSpec.describe RE2::Scanner do
|
|
34
34
|
expect(scanner.scan).to be_nil
|
35
35
|
end
|
36
36
|
|
37
|
+
it "supports scanning inputs with null bytes", :aggregate_failures do
|
38
|
+
r = RE2::Regexp.new("(\\w\0\\w)")
|
39
|
+
scanner = r.scan("a\0b c\0d e\0f")
|
40
|
+
|
41
|
+
expect(scanner.scan).to eq(["a\0b"])
|
42
|
+
expect(scanner.scan).to eq(["c\0d"])
|
43
|
+
expect(scanner.scan).to eq(["e\0f"])
|
44
|
+
expect(scanner.scan).to be_nil
|
45
|
+
end
|
46
|
+
|
37
47
|
it "returns UTF-8 matches if the pattern is UTF-8" do
|
38
48
|
r = RE2::Regexp.new('(\w+)')
|
39
49
|
scanner = r.scan("It")
|
@@ -43,7 +53,7 @@ RSpec.describe RE2::Scanner do
|
|
43
53
|
end
|
44
54
|
|
45
55
|
it "returns ISO-8859-1 matches if the pattern is not UTF-8" do
|
46
|
-
r = RE2::Regexp.new('(\w+)', :
|
56
|
+
r = RE2::Regexp.new('(\w+)', utf8: false)
|
47
57
|
scanner = r.scan("It")
|
48
58
|
matches = scanner.scan
|
49
59
|
|
@@ -75,7 +85,7 @@ RSpec.describe RE2::Scanner do
|
|
75
85
|
end
|
76
86
|
|
77
87
|
it "returns nil if the regexp is invalid" do
|
78
|
-
r = RE2::Regexp.new('???', :
|
88
|
+
r = RE2::Regexp.new('???', log_errors: false)
|
79
89
|
scanner = r.scan("Foo bar")
|
80
90
|
|
81
91
|
expect(scanner.scan).to be_nil
|
@@ -173,12 +183,7 @@ RSpec.describe RE2::Scanner do
|
|
173
183
|
r = RE2::Regexp.new('(\d)')
|
174
184
|
scanner = r.scan("There are 1 some 2 numbers 3")
|
175
185
|
|
176
|
-
|
177
|
-
if defined?(Enumerator)
|
178
|
-
expect(scanner.each).to be_a(Enumerator)
|
179
|
-
elsif defined?(Enumerable::Enumerator)
|
180
|
-
expect(scanner.each).to be_a(Enumerable::Enumerator)
|
181
|
-
end
|
186
|
+
expect(scanner.each).to be_a(Enumerator)
|
182
187
|
end
|
183
188
|
end
|
184
189
|
|
@@ -195,6 +200,18 @@ RSpec.describe RE2::Scanner do
|
|
195
200
|
expect(scanner.to_enum.first).to eq(["1"])
|
196
201
|
end
|
197
202
|
|
203
|
+
it "supports inputs with null bytes", :aggregate_failures do
|
204
|
+
r = RE2::Regexp.new("(\\w\0\\w)")
|
205
|
+
scanner = r.scan("a\0b c\0d")
|
206
|
+
|
207
|
+
expect(scanner.to_enum.first).to eq(["a\0b"])
|
208
|
+
expect(scanner.to_enum.first).to eq(["c\0d"])
|
209
|
+
|
210
|
+
scanner.rewind
|
211
|
+
|
212
|
+
expect(scanner.to_enum.first).to eq(["a\0b"])
|
213
|
+
end
|
214
|
+
|
198
215
|
it "resets the eof? check", :aggregate_failures do
|
199
216
|
r = RE2::Regexp.new('(\d)')
|
200
217
|
scanner = r.scan("1")
|
data/spec/re2/set_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe RE2::Set do
|
2
4
|
describe "#initialize" do
|
3
5
|
it "returns an instance given no args" do
|
@@ -25,7 +27,7 @@ RSpec.describe RE2::Set do
|
|
25
27
|
end
|
26
28
|
|
27
29
|
it "returns an instance given an anchor and options" do
|
28
|
-
set = RE2::Set.new(:unanchored, :
|
30
|
+
set = RE2::Set.new(:unanchored, case_sensitive: false)
|
29
31
|
|
30
32
|
expect(set).to be_a(RE2::Set)
|
31
33
|
end
|
@@ -42,7 +44,7 @@ RSpec.describe RE2::Set do
|
|
42
44
|
end
|
43
45
|
|
44
46
|
it "raises an error if given an invalid anchor and options" do
|
45
|
-
expect { RE2::Set.new(:not_a_valid_anchor, :
|
47
|
+
expect { RE2::Set.new(:not_a_valid_anchor, case_sensitive: false) }.to raise_error(
|
46
48
|
ArgumentError,
|
47
49
|
"anchor should be one of: :unanchored, :anchor_start, :anchor_both"
|
48
50
|
)
|
@@ -59,19 +61,19 @@ RSpec.describe RE2::Set do
|
|
59
61
|
end
|
60
62
|
|
61
63
|
it "rejects invalid patterns when added" do
|
62
|
-
set = RE2::Set.new(:unanchored, :
|
64
|
+
set = RE2::Set.new(:unanchored, log_errors: false)
|
63
65
|
|
64
66
|
expect { set.add("???") }.to raise_error(ArgumentError, /str rejected by RE2::Set->Add\(\)/)
|
65
67
|
end
|
66
68
|
|
67
69
|
it "truncates error messages to 100 characters" do
|
68
|
-
set = RE2::Set.new(:unanchored, :
|
70
|
+
set = RE2::Set.new(:unanchored, log_errors: false)
|
69
71
|
|
70
72
|
expect { set.add("(?P<#{'o' * 200}") }.to raise_error(ArgumentError, "str rejected by RE2::Set->Add(): invalid named capture group: (?P<oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo")
|
71
73
|
end
|
72
74
|
|
73
75
|
it "raises an error if called after #compile" do
|
74
|
-
set = RE2::Set.new(:unanchored, :
|
76
|
+
set = RE2::Set.new(:unanchored, log_errors: false)
|
75
77
|
set.add("abc")
|
76
78
|
set.compile
|
77
79
|
|
@@ -81,7 +83,7 @@ RSpec.describe RE2::Set do
|
|
81
83
|
end
|
82
84
|
|
83
85
|
it "raises an error if given a pattern that can't be coerced to a String" do
|
84
|
-
set = RE2::Set.new(:unanchored, :
|
86
|
+
set = RE2::Set.new(:unanchored, log_errors: false)
|
85
87
|
|
86
88
|
expect { set.add(0) }.to raise_error(TypeError)
|
87
89
|
end
|
@@ -112,7 +114,7 @@ RSpec.describe RE2::Set do
|
|
112
114
|
set.add("ghi")
|
113
115
|
set.compile
|
114
116
|
|
115
|
-
expect(set.match("abcdefghi", :
|
117
|
+
expect(set.match("abcdefghi", exception: false)).to eq([0, 1, 2])
|
116
118
|
end
|
117
119
|
|
118
120
|
it "returns an empty array if there is no match" do
|
@@ -120,7 +122,15 @@ RSpec.describe RE2::Set do
|
|
120
122
|
set.add("abc")
|
121
123
|
set.compile
|
122
124
|
|
123
|
-
expect(set.match("def", :
|
125
|
+
expect(set.match("def", exception: false)).to be_empty
|
126
|
+
end
|
127
|
+
|
128
|
+
it "supports matching null bytes", :aggregate_failures do
|
129
|
+
set = RE2::Set.new
|
130
|
+
set.add("a\0b")
|
131
|
+
set.compile
|
132
|
+
|
133
|
+
expect(set.match("a\0b", exception: false)).to eq([0])
|
124
134
|
end
|
125
135
|
|
126
136
|
it "returns an empty array if there is no match when :exception is true" do
|
@@ -136,7 +146,7 @@ RSpec.describe RE2::Set do
|
|
136
146
|
it "raises an error if called before #compile by default" do
|
137
147
|
skip "Underlying RE2::Set::Match does not output error information" unless RE2::Set.match_raises_errors?
|
138
148
|
|
139
|
-
set = RE2::Set.new(:unanchored, :
|
149
|
+
set = RE2::Set.new(:unanchored, log_errors: false)
|
140
150
|
|
141
151
|
silence_stderr do
|
142
152
|
expect { set.match("") }.to raise_error(RE2::Set::MatchError)
|
@@ -146,28 +156,28 @@ RSpec.describe RE2::Set do
|
|
146
156
|
it "raises an error if called before #compile when :exception is true" do
|
147
157
|
skip "Underlying RE2::Set::Match does not output error information" unless RE2::Set.match_raises_errors?
|
148
158
|
|
149
|
-
set = RE2::Set.new(:unanchored, :
|
159
|
+
set = RE2::Set.new(:unanchored, log_errors: false)
|
150
160
|
|
151
161
|
silence_stderr do
|
152
|
-
expect { set.match("", :
|
162
|
+
expect { set.match("", exception: true) }.to raise_error(RE2::Set::MatchError)
|
153
163
|
end
|
154
164
|
end
|
155
165
|
|
156
166
|
it "returns an empty array if called before #compile when :exception is false" do
|
157
|
-
set = RE2::Set.new(:unanchored, :
|
167
|
+
set = RE2::Set.new(:unanchored, log_errors: false)
|
158
168
|
|
159
169
|
silence_stderr do
|
160
|
-
expect(set.match("", :
|
170
|
+
expect(set.match("", exception: false)).to be_empty
|
161
171
|
end
|
162
172
|
end
|
163
173
|
|
164
|
-
it "raises an error if :exception is true and
|
174
|
+
it "raises an error if :exception is true and RE2 does not support it" do
|
165
175
|
skip "Underlying RE2::Set::Match outputs error information" if RE2::Set.match_raises_errors?
|
166
176
|
|
167
|
-
set = RE2::Set.new(:unanchored, :
|
177
|
+
set = RE2::Set.new(:unanchored, log_errors: false)
|
168
178
|
|
169
179
|
silence_stderr do
|
170
|
-
expect { set.match("", :
|
180
|
+
expect { set.match("", exception: true) }.to raise_error(RE2::Set::UnsupportedError)
|
171
181
|
end
|
172
182
|
end
|
173
183
|
|
@@ -182,7 +192,7 @@ RSpec.describe RE2::Set do
|
|
182
192
|
set.add("abc")
|
183
193
|
set.compile
|
184
194
|
|
185
|
-
expect { set.match(0, :
|
195
|
+
expect { set.match(0, exception: false) }.to raise_error(TypeError)
|
186
196
|
end
|
187
197
|
|
188
198
|
it "accepts input if it can be coerced to a String" do
|
@@ -190,7 +200,7 @@ RSpec.describe RE2::Set do
|
|
190
200
|
set.add("abc")
|
191
201
|
set.compile
|
192
202
|
|
193
|
-
expect(set.match(StringLike.new("abcdef"), :
|
203
|
+
expect(set.match(StringLike.new("abcdef"), exception: false)).to contain_exactly(0)
|
194
204
|
end
|
195
205
|
end
|
196
206
|
|
data/spec/re2/string_spec.rb
CHANGED
data/spec/re2_spec.rb
CHANGED
@@ -1,9 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe RE2 do
|
2
4
|
describe ".Replace" do
|
3
5
|
it "only replaces the first occurrence of the pattern" do
|
4
6
|
expect(RE2.Replace("woo", "o", "a")).to eq("wao")
|
5
7
|
end
|
6
8
|
|
9
|
+
it "supports inputs with null bytes" do
|
10
|
+
expect(RE2.Replace("w\0oo", "o", "a")).to eq("w\0ao")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "supports patterns with null bytes" do
|
14
|
+
expect(RE2.Replace("w\0oo", "\0", "o")).to eq("wooo")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "supports replacements with null bytes" do
|
18
|
+
expect(RE2.Replace("woo", "o", "\0")).to eq("w\0o")
|
19
|
+
end
|
20
|
+
|
7
21
|
it "performs replacement based on regular expressions" do
|
8
22
|
expect(RE2.Replace("woo", "o+", "e")).to eq("we")
|
9
23
|
end
|
@@ -27,7 +41,7 @@ RSpec.describe RE2 do
|
|
27
41
|
end
|
28
42
|
|
29
43
|
it "respects any passed RE2::Regexp's flags" do
|
30
|
-
re = RE2::Regexp.new('gOOD MORNING', :
|
44
|
+
re = RE2::Regexp.new('gOOD MORNING', case_sensitive: false)
|
31
45
|
|
32
46
|
expect(RE2.Replace("Good morning", re, "hi")).to eq("hi")
|
33
47
|
end
|
@@ -53,7 +67,7 @@ RSpec.describe RE2 do
|
|
53
67
|
|
54
68
|
it "returns ISO-8859-1 strings if the pattern is not UTF-8" do
|
55
69
|
original = "Foo"
|
56
|
-
replacement = RE2.Replace(original, RE2("oo", :
|
70
|
+
replacement = RE2.Replace(original, RE2("oo", utf8: false), "ah")
|
57
71
|
|
58
72
|
expect(replacement.encoding).to eq(Encoding::ISO_8859_1)
|
59
73
|
end
|
@@ -82,6 +96,18 @@ RSpec.describe RE2 do
|
|
82
96
|
expect(RE2.GlobalReplace("woo", "o", "a")).to eq("waa")
|
83
97
|
end
|
84
98
|
|
99
|
+
it "supports inputs with null bytes" do
|
100
|
+
expect(RE2.GlobalReplace("w\0oo", "o", "a")).to eq("w\0aa")
|
101
|
+
end
|
102
|
+
|
103
|
+
it "supports patterns with null bytes" do
|
104
|
+
expect(RE2.GlobalReplace("w\0\0oo", "\0", "a")).to eq("waaoo")
|
105
|
+
end
|
106
|
+
|
107
|
+
it "supports replacements with null bytes" do
|
108
|
+
expect(RE2.GlobalReplace("woo", "o", "\0")).to eq("w\0\0")
|
109
|
+
end
|
110
|
+
|
85
111
|
it "performs replacement based on regular expressions" do
|
86
112
|
expect(RE2.GlobalReplace("woohoo", "o+", "e")).to eq("wehe")
|
87
113
|
end
|
@@ -105,7 +131,7 @@ RSpec.describe RE2 do
|
|
105
131
|
end
|
106
132
|
|
107
133
|
it "respects any passed RE2::Regexp's flags" do
|
108
|
-
re = RE2::Regexp.new('gOOD MORNING', :
|
134
|
+
re = RE2::Regexp.new('gOOD MORNING', case_sensitive: false)
|
109
135
|
|
110
136
|
expect(RE2.GlobalReplace("Good morning Good morning", re, "hi")).to eq("hi hi")
|
111
137
|
end
|
@@ -131,7 +157,7 @@ RSpec.describe RE2 do
|
|
131
157
|
|
132
158
|
it "returns ISO-8859-1 strings if the pattern is not UTF-8" do
|
133
159
|
original = "Foo"
|
134
|
-
replacement = RE2.GlobalReplace(original, RE2("oo", :
|
160
|
+
replacement = RE2.GlobalReplace(original, RE2("oo", utf8: false), "ah")
|
135
161
|
|
136
162
|
expect(replacement.encoding).to eq(Encoding::ISO_8859_1)
|
137
163
|
end
|
@@ -167,5 +193,9 @@ RSpec.describe RE2 do
|
|
167
193
|
it "supports passing something that can be coerced to a String as input" do
|
168
194
|
expect(RE2.QuoteMeta(StringLike.new("1.5"))).to eq('1\.5')
|
169
195
|
end
|
196
|
+
|
197
|
+
it "supports strings containing null bytes" do
|
198
|
+
expect(RE2.QuoteMeta("abc\0def")).to eq('abc\x00def')
|
199
|
+
end
|
170
200
|
end
|
171
201
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: re2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Mucur
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-04-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake-compiler
|
@@ -17,28 +17,28 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 1.2.
|
20
|
+
version: 1.2.5
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 1.2.
|
27
|
+
version: 1.2.5
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake-compiler-dock
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 1.
|
34
|
+
version: 1.4.0
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 1.
|
41
|
+
version: 1.4.0
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rspec
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,11 +86,12 @@ files:
|
|
86
86
|
- ext/re2/re2.cc
|
87
87
|
- ext/re2/recipes.rb
|
88
88
|
- lib/re2.rb
|
89
|
+
- lib/re2/regexp.rb
|
89
90
|
- lib/re2/scanner.rb
|
90
91
|
- lib/re2/string.rb
|
91
92
|
- lib/re2/version.rb
|
92
|
-
- ports/archives/
|
93
|
-
- ports/archives/re2-
|
93
|
+
- ports/archives/20240116.1.tar.gz
|
94
|
+
- ports/archives/re2-2024-04-01.tar.gz
|
94
95
|
- re2.gemspec
|
95
96
|
- spec/kernel_spec.rb
|
96
97
|
- spec/re2/match_data_spec.rb
|
@@ -119,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
120
|
- !ruby/object:Gem::Version
|
120
121
|
version: '0'
|
121
122
|
requirements: []
|
122
|
-
rubygems_version: 3.4.
|
123
|
+
rubygems_version: 3.4.19
|
123
124
|
signing_key:
|
124
125
|
specification_version: 4
|
125
126
|
summary: Ruby bindings to RE2.
|
Binary file
|
Binary file
|