re2 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7a33f3c27224496ec131c261c7c66172f21474bce66cdf1cc1631c83040b3ca
4
- data.tar.gz: 4d4a5448aa271bbce4cf37ffadfaadfa0797691fad5cc13f2f722e281116d66f
3
+ metadata.gz: ce0e303b87738a767776165216cbbd8cf0f63ec9dba3ef4389f657cbb5da8dc3
4
+ data.tar.gz: 61983a9e93dc64334d43a41f3f978ff71de020bd9d6f27bc409431a313ea58e0
5
5
  SHA512:
6
- metadata.gz: f080eccb20bb599b374485981f4c23fd8a49e84903ebe32e99e00b458c8b6334430cef41cbb1227fcba057f81d2fed4ead67648e506348fa6c2f975b7e6fea7f
7
- data.tar.gz: bbd0ca07b287ca7e212175b4f5eaafd2698b7be94aefa432e81c4ff108b4b4c660e47d03d48d6affb82c0cee5f98fcb37bdcd97651bf309cebb148ac5e654518
6
+ metadata.gz: 229f667e12094ae2d42ae3d72a08aa0567cf17e1d666d9677b6b0bdfccc549f241870085ac918789fbbcd0fcb538a942a31f6922f32d88cc7b54043b553f35e3
7
+ data.tar.gz: 850d6dc79bcfbfe96a913ac93ddc2c8d4e1b79ddd8aa50eb951bfaae99e3a1688ff31fd2e55c2e497946b9ea4913bcca4938070b6fa37f2ca77d88721652ca66
data/README.md CHANGED
@@ -4,7 +4,7 @@ re2 [![Build Status](https://github.com/mudge/re2/actions/workflows/tests.yml/ba
4
4
  A Ruby binding to [re2][], an "efficient, principled regular expression
5
5
  library".
6
6
 
7
- **Current version:** 1.3.0
7
+ **Current version:** 1.4.0
8
8
  **Supported Ruby versions:** 1.8.7, 1.9.3, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0
9
9
  **Supported re2 versions:** libre2.0 (< 2020-03-02), libre2.1 (2020-03-02), libre2.6 (2020-03-03), libre2.7 (2020-05-01), libre2.8 (2020-07-06), libre2.9 (2020-11-01)
10
10
 
@@ -175,7 +175,9 @@ Contributions
175
175
  * Thanks to [Stefano Rivera](https://github.com/stefanor) who first contributed C++11 support;
176
176
  * Thanks to [Stan Hu](https://github.com/stanhu) for reporting a bug with empty patterns and `RE2::Regexp#scan`;
177
177
  * Thanks to [Sebastian Reitenbach](https://github.com/buzzdeee) for reporting
178
- the deprecation and removal of the `utf8` encoding option in re2.
178
+ the deprecation and removal of the `utf8` encoding option in re2;
179
+ * Thanks to [Sergio Medina](https://github.com/serch) for reporting a bug when
180
+ using `RE2::Scanner#scan` with an invalid regular expression.
179
181
 
180
182
  Contact
181
183
  -------
data/ext/re2/re2.cc CHANGED
@@ -1158,6 +1158,7 @@ static VALUE re2_regexp_named_capturing_groups(VALUE self) {
1158
1158
  * @param [String] text the text to search
1159
1159
  * @param [Fixnum] number_of_matches the number of matches to return
1160
1160
  * @return [RE2::MatchData] the matches
1161
+ * @raise [ArgumentError] if given a negative number of matches
1161
1162
  * @raise [NoMemoryError] if there was not enough memory to allocate the matches
1162
1163
  * @example
1163
1164
  * r = RE2::Regexp.new('w(o)(o)')
@@ -1180,7 +1181,15 @@ static VALUE re2_regexp_match(int argc, VALUE *argv, VALUE self) {
1180
1181
 
1181
1182
  if (RTEST(number_of_matches)) {
1182
1183
  n = NUM2INT(number_of_matches);
1184
+
1185
+ if (n < 0) {
1186
+ rb_raise(rb_eArgError, "number of matches should be >= 0");
1187
+ }
1183
1188
  } else {
1189
+ if (!p->pattern->ok()) {
1190
+ return Qnil;
1191
+ }
1192
+
1184
1193
  n = p->pattern->NumberOfCapturingGroups();
1185
1194
  }
1186
1195
 
@@ -1251,7 +1260,13 @@ static VALUE re2_regexp_scan(VALUE self, VALUE text) {
1251
1260
  c->input = new(nothrow) re2::StringPiece(StringValuePtr(text));
1252
1261
  c->regexp = self;
1253
1262
  c->text = text;
1254
- c->number_of_capturing_groups = p->pattern->NumberOfCapturingGroups();
1263
+
1264
+ if (p->pattern->ok()) {
1265
+ c->number_of_capturing_groups = p->pattern->NumberOfCapturingGroups();
1266
+ } else {
1267
+ c->number_of_capturing_groups = 0;
1268
+ }
1269
+
1255
1270
  c->eof = false;
1256
1271
 
1257
1272
  return scanner;
@@ -13,6 +13,11 @@ RSpec.describe RE2::Regexp do
13
13
  it "raises an error if given an inappropriate type" do
14
14
  expect { RE2::Regexp.new(nil) }.to raise_error(TypeError)
15
15
  end
16
+
17
+ it "allows invalid patterns to be created" do
18
+ re = RE2::Regexp.new('???', :log_errors => false)
19
+ expect(re).to be_a(RE2::Regexp)
20
+ end
16
21
  end
17
22
 
18
23
  describe "#compile" do
@@ -25,6 +30,11 @@ RSpec.describe RE2::Regexp do
25
30
  re = RE2::Regexp.compile('woo', :case_sensitive => false)
26
31
  expect(re).to be_a(RE2::Regexp)
27
32
  end
33
+
34
+ it "allows invalid patterns to be created" do
35
+ re = RE2::Regexp.compile('???', :log_errors => false)
36
+ expect(re).to be_a(RE2::Regexp)
37
+ end
28
38
  end
29
39
 
30
40
  describe "#options" do
@@ -83,6 +93,11 @@ RSpec.describe RE2::Regexp do
83
93
  program_size = RE2::Regexp.new('w(o)(o)').program_size
84
94
  expect(program_size).to be_a(Fixnum)
85
95
  end
96
+
97
+ it "returns -1 for an invalid pattern" do
98
+ program_size = RE2::Regexp.new('???', :log_errors => false).program_size
99
+ expect(program_size).to eq(-1)
100
+ end
86
101
  end
87
102
 
88
103
  describe "#to_str" do
@@ -97,6 +112,11 @@ RSpec.describe RE2::Regexp do
97
112
  pattern = RE2::Regexp.new('w(o)(o)').pattern
98
113
  expect(pattern).to eq("w(o)(o)")
99
114
  end
115
+
116
+ it "returns the pattern even if invalid" do
117
+ pattern = RE2::Regexp.new('???', :log_errors => false).pattern
118
+ expect(pattern).to eq("???")
119
+ end
100
120
  end
101
121
 
102
122
  describe "#inspect" do
@@ -274,6 +294,15 @@ RSpec.describe RE2::Regexp do
274
294
  expect { re.match("My name is Robert Paulson", {}) }.to raise_error(TypeError)
275
295
  end
276
296
 
297
+ it "raises an exception when given a negative number of matches" do
298
+ expect { re.match("My name is Robert Paulson", -1) }.to raise_error(ArgumentError, "number of matches should be >= 0")
299
+ end
300
+
301
+ it "returns nil with an invalid pattern" do
302
+ re = RE2::Regexp.new('???', :log_errors => false)
303
+ expect(re.match('My name is Robert Paulson')).to be_nil
304
+ end
305
+
277
306
  describe "with a specific number of matches under the total in the pattern" do
278
307
  subject { re.match("My name is Robert Paulson", 1) }
279
308
 
@@ -325,6 +354,11 @@ RSpec.describe RE2::Regexp do
325
354
  expect(re.match?("My name is Robert Paulson")).to eq(true)
326
355
  expect(re.match?("My age is 99")).to eq(false)
327
356
  end
357
+
358
+ it "returns false if the pattern is invalid" do
359
+ re = RE2::Regexp.new('???', :log_errors => false)
360
+ expect(re.match?("My name is Robert Paulson")).to eq(false)
361
+ end
328
362
  end
329
363
 
330
364
  describe "#=~" do
@@ -365,13 +399,13 @@ RSpec.describe RE2::Regexp do
365
399
  end
366
400
  end
367
401
 
368
- describe "#escape" do
402
+ describe ".escape" do
369
403
  it "transforms a string into a regexp" do
370
404
  expect(RE2::Regexp.escape("1.5-2.0?")).to eq('1\.5\-2\.0\?')
371
405
  end
372
406
  end
373
407
 
374
- describe "#quote" do
408
+ describe ".quote" do
375
409
  it "transforms a string into a regexp" do
376
410
  expect(RE2::Regexp.quote("1.5-2.0?")).to eq('1\.5\-2\.0\?')
377
411
  end
@@ -383,6 +417,10 @@ RSpec.describe RE2::Regexp do
383
417
  expect(RE2::Regexp.new('abc').number_of_capturing_groups).to eq(0)
384
418
  expect(RE2::Regexp.new('a((b)c)').number_of_capturing_groups).to eq(2)
385
419
  end
420
+
421
+ it "returns -1 for an invalid regexp" do
422
+ expect(RE2::Regexp.new('???', :log_errors => false).number_of_capturing_groups).to eq(-1)
423
+ end
386
424
  end
387
425
 
388
426
  describe "#named_capturing_groups" do
@@ -400,6 +438,10 @@ RSpec.describe RE2::Regexp do
400
438
  expect(groups["bob"]).to eq(1)
401
439
  expect(groups["rob"]).to eq(3)
402
440
  end
441
+
442
+ it "returns an empty hash for an invalid regexp" do
443
+ expect(RE2::Regexp.new('???', :log_errors => false).named_capturing_groups).to be_empty
444
+ end
403
445
  end
404
446
 
405
447
  describe "#scan" do
@@ -45,6 +45,12 @@ RSpec.describe RE2::Scanner do
45
45
  expect(scanner.scan).to be_nil
46
46
  end
47
47
 
48
+ it "returns nil if the regexp is invalid" do
49
+ r = RE2::Regexp.new('???', :log_errors => false)
50
+ scanner = r.scan("Foo bar")
51
+ expect(scanner.scan).to be_nil
52
+ end
53
+
48
54
  it "returns an empty array if the input is empty" do
49
55
  r = RE2::Regexp.new("")
50
56
  scanner = r.scan("")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: re2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Mucur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-12 00:00:00.000000000 Z
11
+ date: 2021-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  requirements: []
82
- rubygems_version: 3.1.4
82
+ rubygems_version: 3.2.3
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: Ruby bindings to re2.