re2 2.21.0 → 2.23.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5dfceb5a4a7fe43aa7451c4a0f9876bdab549e0b9dcb1bcbe0203ef55f2e85a
4
- data.tar.gz: 051a6cb4816ff3409efefc39b0101dd9b5bc80fe1ca8ee41bda6d718f3a7a924
3
+ metadata.gz: 940bde937a78abda3052eb0957885f3f190310fcd16fd6408cab7796994bd008
4
+ data.tar.gz: a1847bd0e009e2e4a63395e9452b3ecf39d938922549cc2d8477a9398c1661b6
5
5
  SHA512:
6
- metadata.gz: 92026d27dc2bdaf9db32e0d0271ed90356eed3cdeac1eea21aa8d375a20157a1e3ba84a7e816fbd5bbd41ed3a140ef735852e779c84dd3fb7fe0d0b6046684d5
7
- data.tar.gz: 3ea496e20e67c240e522fbbba7a45bbf0c3fcb668ec242fd7594ab422bbcd734ddddf2c62590e403bbca6eb96748f2b122dbdc36dc202038207279b89ec1ee96
6
+ metadata.gz: 360dc102ebb6ee640bc4c45c8e17f0d22a5b2288c37c40e1288384275214b2c2d72c14ba490ee06472b2ecb9790fbfb5a9a3f7afc35df27aac516b3d4416e302
7
+ data.tar.gz: 02f43ce9a57cee1b1c3c068f3f66c12c029a0bc22b5af00d837fc1bb2fa5fb90e120dc9bf3287adb3f99302fd0f0dd32af5303fd0e7780f41961f2f7a8429ff5
data/README.md CHANGED
@@ -6,7 +6,7 @@ Python".
6
6
 
7
7
  [![Build Status](https://github.com/mudge/re2/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/mudge/re2/actions)
8
8
 
9
- **Current version:** 2.21.0
9
+ **Current version:** 2.23.0
10
10
  **Bundled RE2 version:** libre2.11 (2025-11-05)
11
11
 
12
12
  ```ruby
@@ -260,7 +260,7 @@ RE2(non_latin1_pattern.encode("ISO-8859-1"), utf8: false).match(non_latin1_text.
260
260
 
261
261
  This gem requires the following to run:
262
262
 
263
- * [Ruby](https://www.ruby-lang.org/en/) 3.1 to 3.4
263
+ * [Ruby](https://www.ruby-lang.org/en/) 3.1 to 4.0
264
264
 
265
265
  It supports the following RE2 ABI versions:
266
266
 
data/Rakefile CHANGED
@@ -33,7 +33,7 @@ cross_platforms = %w[
33
33
  x86_64-linux-musl
34
34
  ].freeze
35
35
 
36
- RakeCompilerDock.set_ruby_cc_version("~> 3.1")
36
+ RakeCompilerDock.set_ruby_cc_version("~> 3.1", "~> 4.0")
37
37
 
38
38
  Gem::PackageTask.new(re2_gemspec).define
39
39
 
@@ -74,7 +74,6 @@ namespace :gem do
74
74
  echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ focal main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null &&
75
75
  sudo apt-get update &&
76
76
  sudo apt-get install -y cmake=3.22.2-0kitware1ubuntu20.04.1 cmake-data=3.22.2-0kitware1ubuntu20.04.1 &&
77
- rbenv shell 3.1.6 &&
78
77
  gem install bundler --no-document &&
79
78
  bundle install &&
80
79
  bundle exec rake native:#{platform} pkg/#{re2_gemspec.full_name}-#{Gem::Platform.new(platform)}.gem PATH="/usr/local/bin:$PATH"
data/ext/re2/re2.cc CHANGED
@@ -326,6 +326,11 @@ static VALUE re2_scanner_rewind(VALUE self) {
326
326
  delete c->input;
327
327
  c->input = new(std::nothrow) re2::StringPiece(
328
328
  RSTRING_PTR(c->text), RSTRING_LEN(c->text));
329
+ if (c->input == 0) {
330
+ rb_raise(rb_eNoMemError,
331
+ "not enough memory to allocate StringPiece for input");
332
+ }
333
+
329
334
  c->eof = false;
330
335
 
331
336
  return self;
@@ -412,8 +417,8 @@ static re2::StringPiece *re2_matchdata_find_match(VALUE idx, const VALUE self) {
412
417
 
413
418
  int id;
414
419
 
415
- if (FIXNUM_P(idx)) {
416
- id = FIX2INT(idx);
420
+ if (RB_INTEGER_TYPE_P(idx)) {
421
+ id = NUM2INT(idx);
417
422
  } else if (SYMBOL_P(idx)) {
418
423
  const std::map<std::string, int>& groups = p->pattern->NamedCapturingGroups();
419
424
  std::map<std::string, int>::const_iterator search = groups.find(rb_id2name(SYM2ID(idx)));
@@ -681,10 +686,10 @@ static VALUE re2_matchdata_aref(int argc, VALUE *argv, const VALUE self) {
681
686
  std::string(RSTRING_PTR(idx), RSTRING_LEN(idx)), self);
682
687
  } else if (SYMBOL_P(idx)) {
683
688
  return re2_matchdata_named_match(rb_id2name(SYM2ID(idx)), self);
684
- } else if (!NIL_P(rest) || !FIXNUM_P(idx) || FIX2INT(idx) < 0) {
689
+ } else if (!NIL_P(rest) || !RB_INTEGER_TYPE_P(idx) || NUM2INT(idx) < 0) {
685
690
  return rb_ary_aref(argc, argv, re2_matchdata_to_a(self));
686
691
  } else {
687
- return re2_matchdata_nth_match(FIX2INT(idx), self);
692
+ return re2_matchdata_nth_match(NUM2INT(idx), self);
688
693
  }
689
694
  }
690
695
 
@@ -1421,7 +1426,7 @@ static VALUE re2_regexp_match(int argc, VALUE *argv, const VALUE self) {
1421
1426
  RE2::Anchor anchor = RE2::UNANCHORED;
1422
1427
 
1423
1428
  if (RTEST(options)) {
1424
- if (FIXNUM_P(options)) {
1429
+ if (RB_INTEGER_TYPE_P(options)) {
1425
1430
  n = NUM2INT(options);
1426
1431
 
1427
1432
  if (n < 0) {
@@ -1435,8 +1440,6 @@ static VALUE re2_regexp_match(int argc, VALUE *argv, const VALUE self) {
1435
1440
  VALUE endpos_option = rb_hash_aref(options, ID2SYM(id_endpos));
1436
1441
  if (!NIL_P(endpos_option)) {
1437
1442
  #ifdef HAVE_ENDPOS_ARGUMENT
1438
- Check_Type(endpos_option, T_FIXNUM);
1439
-
1440
1443
  endpos = NUM2INT(endpos_option);
1441
1444
 
1442
1445
  if (endpos < 0) {
@@ -1465,8 +1468,6 @@ static VALUE re2_regexp_match(int argc, VALUE *argv, const VALUE self) {
1465
1468
 
1466
1469
  VALUE submatches_option = rb_hash_aref(options, ID2SYM(id_submatches));
1467
1470
  if (!NIL_P(submatches_option)) {
1468
- Check_Type(submatches_option, T_FIXNUM);
1469
-
1470
1471
  n = NUM2INT(submatches_option);
1471
1472
 
1472
1473
  if (n < 0) {
@@ -1482,8 +1483,6 @@ static VALUE re2_regexp_match(int argc, VALUE *argv, const VALUE self) {
1482
1483
 
1483
1484
  VALUE startpos_option = rb_hash_aref(options, ID2SYM(id_startpos));
1484
1485
  if (!NIL_P(startpos_option)) {
1485
- Check_Type(startpos_option, T_FIXNUM);
1486
-
1487
1486
  startpos = NUM2INT(startpos_option);
1488
1487
 
1489
1488
  if (startpos < 0) {
@@ -1515,37 +1514,43 @@ static VALUE re2_regexp_match(int argc, VALUE *argv, const VALUE self) {
1515
1514
  #endif
1516
1515
  return BOOL2RUBY(matched);
1517
1516
  } else {
1517
+ if (n == INT_MAX) {
1518
+ rb_raise(rb_eRangeError, "number of matches should be < %d", INT_MAX);
1519
+ }
1520
+
1518
1521
  /* Because match returns the whole match as well. */
1519
1522
  n += 1;
1520
1523
 
1521
- VALUE matchdata = rb_class_new_instance(0, 0, re2_cMatchData);
1522
- TypedData_Get_Struct(matchdata, re2_matchdata, &re2_matchdata_data_type, m);
1523
- m->matches = new(std::nothrow) re2::StringPiece[n];
1524
- RB_OBJ_WRITE(matchdata, &m->regexp, self);
1525
- if (!RTEST(rb_obj_frozen_p(text))) {
1526
- text = rb_str_freeze(rb_str_dup(text));
1527
- }
1528
- RB_OBJ_WRITE(matchdata, &m->text, text);
1529
-
1530
- if (m->matches == 0) {
1524
+ re2::StringPiece *matches = new(std::nothrow) re2::StringPiece[n];
1525
+ if (matches == 0) {
1531
1526
  rb_raise(rb_eNoMemError,
1532
1527
  "not enough memory to allocate StringPieces for matches");
1533
1528
  }
1534
1529
 
1535
- m->number_of_matches = n;
1530
+ text = rb_str_new_frozen(text);
1536
1531
 
1537
1532
  #ifdef HAVE_ENDPOS_ARGUMENT
1538
1533
  bool matched = p->pattern->Match(
1539
- re2::StringPiece(RSTRING_PTR(m->text), RSTRING_LEN(m->text)),
1540
- startpos, endpos, anchor, m->matches, n);
1534
+ re2::StringPiece(RSTRING_PTR(text), RSTRING_LEN(text)),
1535
+ startpos, endpos, anchor, matches, n);
1541
1536
  #else
1542
1537
  bool matched = p->pattern->Match(
1543
- re2::StringPiece(RSTRING_PTR(m->text), RSTRING_LEN(m->text)),
1544
- startpos, anchor, m->matches, n);
1538
+ re2::StringPiece(RSTRING_PTR(text), RSTRING_LEN(text)),
1539
+ startpos, anchor, matches, n);
1545
1540
  #endif
1546
1541
  if (matched) {
1542
+ VALUE matchdata = rb_class_new_instance(0, 0, re2_cMatchData);
1543
+ TypedData_Get_Struct(matchdata, re2_matchdata, &re2_matchdata_data_type, m);
1544
+
1545
+ RB_OBJ_WRITE(matchdata, &m->regexp, self);
1546
+ RB_OBJ_WRITE(matchdata, &m->text, text);
1547
+ m->matches = matches;
1548
+ m->number_of_matches = n;
1549
+
1547
1550
  return matchdata;
1548
1551
  } else {
1552
+ delete[] matches;
1553
+
1549
1554
  return Qnil;
1550
1555
  }
1551
1556
  }
@@ -1615,12 +1620,13 @@ static VALUE re2_regexp_scan(const VALUE self, VALUE text) {
1615
1620
  TypedData_Get_Struct(scanner, re2_scanner, &re2_scanner_data_type, c);
1616
1621
 
1617
1622
  RB_OBJ_WRITE(scanner, &c->regexp, self);
1618
- if (!RTEST(rb_obj_frozen_p(text))) {
1619
- text = rb_str_freeze(rb_str_dup(text));
1620
- }
1621
- RB_OBJ_WRITE(scanner, &c->text, text);
1623
+ RB_OBJ_WRITE(scanner, &c->text, rb_str_new_frozen(text));
1622
1624
  c->input = new(std::nothrow) re2::StringPiece(
1623
- RSTRING_PTR(text), RSTRING_LEN(text));
1625
+ RSTRING_PTR(c->text), RSTRING_LEN(c->text));
1626
+ if (c->input == 0) {
1627
+ rb_raise(rb_eNoMemError,
1628
+ "not enough memory to allocate StringPiece for input");
1629
+ }
1624
1630
 
1625
1631
  if (p->pattern->ok()) {
1626
1632
  c->number_of_capturing_groups = p->pattern->NumberOfCapturingGroups();
@@ -1916,21 +1922,19 @@ static VALUE re2_set_add(VALUE self, VALUE pattern) {
1916
1922
  re2_set *s;
1917
1923
  TypedData_Get_Struct(self, re2_set, &re2_set_data_type, s);
1918
1924
 
1919
- /* To prevent the memory of the err string leaking when we call rb_raise,
1920
- * take a copy of it and let it go out of scope.
1921
- */
1922
- char msg[100];
1923
1925
  int index;
1926
+ VALUE msg;
1924
1927
 
1925
1928
  {
1926
1929
  std::string err;
1927
1930
  index = s->set->Add(
1928
1931
  re2::StringPiece(RSTRING_PTR(pattern), RSTRING_LEN(pattern)), &err);
1929
- strlcpy(msg, err.c_str(), sizeof(msg));
1932
+ msg = rb_str_new(err.data(), err.size());
1930
1933
  }
1931
1934
 
1932
1935
  if (index < 0) {
1933
- rb_raise(rb_eArgError, "str rejected by RE2::Set->Add(): %s", msg);
1936
+ rb_raise(rb_eArgError,
1937
+ "str rejected by RE2::Set->Add(): %s", RSTRING_PTR(msg));
1934
1938
  }
1935
1939
 
1936
1940
  return INT2FIX(index);
data/lib/re2/version.rb CHANGED
@@ -10,5 +10,5 @@
10
10
 
11
11
 
12
12
  module RE2
13
- VERSION = "2.21.0"
13
+ VERSION = "2.23.0"
14
14
  end
data/re2.gemspec CHANGED
@@ -40,8 +40,8 @@ Gem::Specification.new do |s|
40
40
  "spec/re2/set_spec.rb",
41
41
  "spec/re2/scanner_spec.rb"
42
42
  ]
43
- s.add_development_dependency("rake-compiler", "~> 1.3.0")
44
- s.add_development_dependency("rake-compiler-dock", "~> 1.9.1")
43
+ s.add_development_dependency("rake-compiler", "~> 1.3.1")
44
+ s.add_development_dependency("rake-compiler-dock", "~> 1.11.0")
45
45
  s.add_development_dependency("rspec", "~> 3.2")
46
46
  s.add_runtime_dependency("mini_portile2", "~> 2.8.9") # keep version in sync with extconf.rb
47
47
  end
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rbconfig/sizeof"
4
+
3
5
  RSpec.describe RE2::Regexp do
6
+ INT_MAX = 2**(RbConfig::SIZEOF.fetch("int") * 8 - 1) - 1
7
+
4
8
  describe "#initialize" do
5
9
  it "returns an instance given only a pattern" do
6
10
  re = RE2::Regexp.new('woo')
@@ -566,6 +570,12 @@ RSpec.describe RE2::Regexp do
566
570
  expect { re.match("one two three", submatches: :invalid) }.to raise_error(TypeError)
567
571
  end
568
572
 
573
+ it "raises an exception when given too large a number of submatches" do
574
+ re = RE2::Regexp.new('(\w+) (\w+) (\w+)')
575
+
576
+ expect { re.match("one two three", submatches: INT_MAX) }.to raise_error(RangeError, "number of matches should be < #{INT_MAX}")
577
+ end
578
+
569
579
  it "defaults to extracting all submatches when given nil", :aggregate_failures do
570
580
  re = RE2::Regexp.new('(\w+) (\w+) (\w+)')
571
581
  md = re.match("one two three", submatches: nil)
@@ -584,6 +594,13 @@ RSpec.describe RE2::Regexp do
584
594
  expect(md[3]).to be_nil
585
595
  end
586
596
 
597
+ it "raises an exception if given too large a number of submatches instead of options" do
598
+ re = RE2::Regexp.new('(\w+) (\w+) (\w+)')
599
+ md = re.match("one two three", 2)
600
+
601
+ expect { re.match("one two three", INT_MAX) }.to raise_error(RangeError, "number of matches should be < #{INT_MAX}")
602
+ end
603
+
587
604
  it "raises an exception when given invalid options" do
588
605
  re = RE2::Regexp.new('(\w+) (\w+) (\w+)')
589
606
 
data/spec/re2/set_spec.rb CHANGED
@@ -66,10 +66,10 @@ RSpec.describe RE2::Set do
66
66
  expect { set.add("???") }.to raise_error(ArgumentError, /str rejected by RE2::Set->Add\(\)/)
67
67
  end
68
68
 
69
- it "truncates error messages to 100 characters" do
69
+ it "includes the full error message" do
70
70
  set = RE2::Set.new(:unanchored, log_errors: false)
71
71
 
72
- expect { set.add("(?P<#{'o' * 200}") }.to raise_error(ArgumentError, "str rejected by RE2::Set->Add(): invalid named capture group: (?P<oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo")
72
+ expect { set.add("(?P<#{'o' * 200}") }.to raise_error(ArgumentError, "str rejected by RE2::Set->Add(): invalid named capture group: (?P<oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo")
73
73
  end
74
74
 
75
75
  it "raises an error if called after #compile" do
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.21.0
4
+ version: 2.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Mucur
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3.0
19
+ version: 1.3.1
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.3.0
26
+ version: 1.3.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake-compiler-dock
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.9.1
33
+ version: 1.11.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.9.1
40
+ version: 1.11.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.6.9
120
+ rubygems_version: 4.0.3
121
121
  specification_version: 4
122
122
  summary: Ruby bindings to RE2.
123
123
  test_files: