re2 2.21.0-arm-linux-gnu → 2.22.0-arm-linux-gnu

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: dbdd9a1a46ac6e196b2bbf90e31684c9559f87d9ab4febad73a5f4cf34c9ed77
4
- data.tar.gz: 44e9874ed9f6e4454d5707144553d1abd79be711fdfcea9727bb2480179d9924
3
+ metadata.gz: 83f94d7b94283ab5cd0b89ee9b0e3749aa3b7757fe6520b8c680d6ef11584a6b
4
+ data.tar.gz: 878457fb7ab4cbd81d5d4953637581b248ce1e0c8a576905ac96da3945c6cf05
5
5
  SHA512:
6
- metadata.gz: 283e6f9ae2614b8ac86d0dda2fcb8b3f24f52ea4a0bfd1a0abfef467a5aed358408adc8718ae35357c885b39e8e197a39129556d9e07bc69c1d9ff19b05a2ecf
7
- data.tar.gz: 6b98326df023569622d7906f1a4b7e83a2a8c0038413aaad6cc9ea2f1200f6340adb927313818c600bbe84ebcae3a7d2819cc7d773e9c82a9458993c00aad437
6
+ metadata.gz: 3955f1d2eba7052e5c6c94f54314212a8756c2c3f8a2f034c3b9c61d40193d2918bc5c83c68025fbbdb178ab40dd19b38102c9b042687f5ecca37e5c4138fe0a
7
+ data.tar.gz: a97b2d4b5a02b9844b8201bbe3d7f2da60534cf84b616f761357257042bb1cb6db5169f0aeb8214e8c538fc4dd100b2de1c1a5ba92e406794b49b22de52c6e49
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.22.0
10
10
  **Bundled RE2 version:** libre2.11 (2025-11-05)
11
11
 
12
12
  ```ruby
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/3.1/re2.so CHANGED
Binary file
data/lib/3.2/re2.so CHANGED
Binary file
data/lib/3.3/re2.so CHANGED
Binary file
data/lib/3.4/re2.so CHANGED
Binary file
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.22.0"
14
14
  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.22.0
5
5
  platform: arm-linux-gnu
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: 2025-11-10 00:00:00.000000000 Z
12
+ date: 2025-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler