re2 2.1.2-x86_64-linux → 2.2.0-x86_64-linux

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: 76feae9ec4f5577a7c36c35a3d1c64759a1819e3f8e92eb178d0fa17e0a3d724
4
- data.tar.gz: 6ea75776e67830df6709a6589f023018f2e2d0a285b995ca4d0766d5aa7c0613
3
+ metadata.gz: e9960963e5a225b22f605c8faae29f1d4cf14500479773e79cd8a16b9dead25f
4
+ data.tar.gz: 519de12c2db8a7a801b901b1a4b924dd45b727f2303eb0aafb7b1b42043b47a8
5
5
  SHA512:
6
- metadata.gz: a4b5a6bbf14b798d7155c7d99babd596dd2f572cfd078c70344210b27a61aa17fd78876ba3a9d14cc86a734889dc9ed1514fb1d5631f639ff315039df61f5dea
7
- data.tar.gz: 0b2cf44841ff83feef33f9049baf275f9ee36224806dab3c643ddeaf35b15a0afafbde21ced6c788d006da538da871f6a2bec91f7af4407876c66bfd2dc4a307
6
+ metadata.gz: 205b56ec06da2e759f9e1436552c3cd2ea3fa1d4905052d867b125c7cc7064fb2708b32a2da9aab40b4871a0207d725fb2fbbc0b90cc7fea59a41662dcadd1e8
7
+ data.tar.gz: 815b6a188aa125712c86e3ccae9bbd4e64e26eafd4d18c276f90d424a5685d26a7e1c675d6ba95bdcc8140869b2ee36751b339a21a5e61e68579f924b2cbe576
data/README.md CHANGED
@@ -5,7 +5,7 @@ Ruby bindings to [RE2][], a "fast, safe, thread-friendly alternative to
5
5
  backtracking regular expression engines like those used in PCRE, Perl, and
6
6
  Python".
7
7
 
8
- **Current version:** 2.1.2
8
+ **Current version:** 2.2.0
9
9
  **Supported Ruby versions:** 2.6, 2.7, 3.0, 3.1, 3.2
10
10
  **Bundled RE2 version:** libre2.11 (2023-09-01)
11
11
  **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), libre2.10 (2022-12-01), libre2.11 (2023-07-01)
@@ -264,6 +264,11 @@ Contributions
264
264
  using `RE2::Scanner#scan` with an invalid regular expression;
265
265
  * Thanks to [Pritam Baral](https://github.com/pritambaral) for contributing the
266
266
  initial support for `RE2::Set`.
267
+ * Thanks to [Mike Dalessio](https://github.com/flavorjones) for reviewing the
268
+ precompilation of native gems in 2.0.
269
+ * Thanks to [Peter Zhu](https://github.com/peterzhu2118) for
270
+ [ruby_memcheck](https://github.com/Shopify/ruby_memcheck) and helping find
271
+ the memory leaks fixed in 2.1.3.
267
272
 
268
273
  Contact
269
274
  -------
data/dependencies.yml CHANGED
@@ -1,9 +1,7 @@
1
+ ---
1
2
  libre2:
2
- version: "2023-09-01"
3
- sha256: "5bb6875ae1cd1e9fedde98018c346db7260655f86fdb8837e3075103acd3649b"
4
- # sha-256 hash provided in https://github.com/google/re2/releases/download/2023-09-01/re2-2023-09-01.tar.gz
5
-
3
+ version: '2023-09-01'
4
+ sha256: 5bb6875ae1cd1e9fedde98018c346db7260655f86fdb8837e3075103acd3649b
6
5
  abseil:
7
- version: "20230125.3"
8
- sha256: 5366d7e7fa7ba0d915014d387b66d0d002c03236448e1ba9ef98122c13b35c36
9
- # sha-256 hash provided in https://github.com/abseil/abseil-cpp/archive/refs/tags/20230125.3.tar.gz
6
+ version: '20230802.1'
7
+ sha256: 987ce98f02eefbaf930d6e38ab16aa05737234d7afbab2d5c4ea7adbe50c28ed
data/ext/re2/extconf.rb CHANGED
@@ -296,17 +296,18 @@ ABSL_LDFLAGS = %w[
296
296
  -labsl_crc32c
297
297
  -labsl_crc_internal
298
298
  -labsl_crc_cpu_detect
299
+ -labsl_raw_hash_set
299
300
  -labsl_hash
300
301
  -labsl_city
301
302
  -labsl_bad_variant_access
302
303
  -labsl_low_level_hash
303
- -labsl_raw_hash_set
304
304
  -labsl_hashtablez_sampler
305
305
  -labsl_exponential_biased
306
306
  -labsl_bad_optional_access
307
307
  -labsl_str_format_internal
308
308
  -labsl_synchronization
309
309
  -labsl_graphcycles_internal
310
+ -labsl_kernel_timeout_internal
310
311
  -labsl_stacktrace
311
312
  -labsl_symbolize
312
313
  -ldbghelp
@@ -316,9 +317,10 @@ ABSL_LDFLAGS = %w[
316
317
  -labsl_time
317
318
  -labsl_civil_time
318
319
  -labsl_strings
320
+ -labsl_string_view
319
321
  -labsl_strings_internal
320
- -ladvapi32
321
322
  -labsl_base
323
+ -ladvapi32
322
324
  -labsl_spinlock_wait
323
325
  -labsl_int128
324
326
  -labsl_throw_delegate
@@ -396,6 +398,8 @@ def build_with_vendored_libraries
396
398
 
397
399
  process_recipe(abseil_recipe) do |recipe|
398
400
  recipe.configure_options += ['-DABSL_PROPAGATE_CXX_STD=ON', '-DCMAKE_CXX_VISIBILITY_PRESET=hidden']
401
+ # Workaround for https://github.com/abseil/abseil-cpp/issues/1510
402
+ recipe.configure_options += ['-DCMAKE_CXX_FLAGS=-DABSL_FORCE_WAITER_MODE=4'] if windows?
399
403
  end
400
404
 
401
405
  process_recipe(re2_recipe) do |recipe|
data/ext/re2/re2.cc CHANGED
@@ -19,7 +19,6 @@
19
19
  #include <ruby/encoding.h>
20
20
 
21
21
  #define BOOL2RUBY(v) (v ? Qtrue : Qfalse)
22
- #define UNUSED(x) ((void)x)
23
22
 
24
23
  typedef struct {
25
24
  RE2 *pattern;
@@ -228,7 +227,8 @@ static VALUE re2_scanner_rewind(VALUE self) {
228
227
  re2_scanner *c;
229
228
  Data_Get_Struct(self, re2_scanner, c);
230
229
 
231
- c->input = new(std::nothrow) re2::StringPiece(StringValuePtr(c->text));
230
+ delete c->input;
231
+ c->input = new(std::nothrow) re2::StringPiece(RSTRING_PTR(c->text));
232
232
  c->eof = false;
233
233
 
234
234
  return self;
@@ -270,7 +270,7 @@ static VALUE re2_scanner_scan(VALUE self) {
270
270
  args[i] = &argv[i];
271
271
  }
272
272
 
273
- if (RE2::FindAndConsumeN(c->input, *p->pattern, &args[0],
273
+ if (RE2::FindAndConsumeN(c->input, *p->pattern, args.data(),
274
274
  c->number_of_capturing_groups)) {
275
275
  re2::StringPiece::size_type new_input_size = c->input->size();
276
276
  bool input_advanced = new_input_size < original_input_size;
@@ -373,9 +373,9 @@ static VALUE re2_matchdata_begin(const VALUE self, VALUE n) {
373
373
  if (match == NULL) {
374
374
  return Qnil;
375
375
  } else {
376
- long offset = match->data() - StringValuePtr(m->text);
376
+ long offset = match->data() - RSTRING_PTR(m->text);
377
377
 
378
- return LONG2NUM(rb_str_sublen(StringValue(m->text), offset));
378
+ return LONG2NUM(rb_str_sublen(m->text, offset));
379
379
  }
380
380
  }
381
381
 
@@ -398,9 +398,9 @@ static VALUE re2_matchdata_end(const VALUE self, VALUE n) {
398
398
  if (match == NULL) {
399
399
  return Qnil;
400
400
  } else {
401
- long offset = (match->data() - StringValuePtr(m->text)) + match->size();
401
+ long offset = (match->data() - RSTRING_PTR(m->text)) + match->size();
402
402
 
403
- return LONG2NUM(rb_str_sublen(StringValue(m->text), offset));
403
+ return LONG2NUM(rb_str_sublen(m->text, offset));
404
404
  }
405
405
  }
406
406
 
@@ -564,7 +564,7 @@ static VALUE re2_matchdata_aref(int argc, VALUE *argv, const VALUE self) {
564
564
  rb_scan_args(argc, argv, "11", &idx, &rest);
565
565
 
566
566
  if (TYPE(idx) == T_STRING) {
567
- return re2_matchdata_named_match(StringValuePtr(idx), self);
567
+ return re2_matchdata_named_match(RSTRING_PTR(idx), self);
568
568
  } else if (SYMBOL_P(idx)) {
569
569
  return re2_matchdata_named_match(rb_id2name(SYM2ID(idx)), self);
570
570
  } else if (!NIL_P(rest) || !FIXNUM_P(idx) || FIX2INT(idx) < 0) {
@@ -617,7 +617,7 @@ static VALUE re2_matchdata_inspect(const VALUE self) {
617
617
  if (match == Qnil) {
618
618
  output << "nil";
619
619
  } else {
620
- output << "\"" << StringValuePtr(match) << "\"";
620
+ output << "\"" << RSTRING_PTR(match) << "\"";
621
621
  }
622
622
  }
623
623
 
@@ -742,9 +742,7 @@ static VALUE re2_matchdata_deconstruct_keys(const VALUE self, const VALUE keys)
742
742
  * @see RE2::Regexp#initialize
743
743
  *
744
744
  */
745
- static VALUE re2_re2(int argc, VALUE *argv, VALUE self) {
746
- UNUSED(self);
747
-
745
+ static VALUE re2_re2(int argc, VALUE *argv, VALUE) {
748
746
  return rb_class_new_instance(argc, argv, re2_cRegexp);
749
747
  }
750
748
 
@@ -788,15 +786,19 @@ static VALUE re2_regexp_initialize(int argc, VALUE *argv, VALUE self) {
788
786
  re2_pattern *p;
789
787
 
790
788
  rb_scan_args(argc, argv, "11", &pattern, &options);
789
+
790
+ /* Ensure pattern is a string. */
791
+ StringValue(pattern);
792
+
791
793
  Data_Get_Struct(self, re2_pattern, p);
792
794
 
793
795
  if (RTEST(options)) {
794
796
  RE2::Options re2_options;
795
797
  parse_re2_options(&re2_options, options);
796
798
 
797
- p->pattern = new(std::nothrow) RE2(StringValuePtr(pattern), re2_options);
799
+ p->pattern = new(std::nothrow) RE2(RSTRING_PTR(pattern), re2_options);
798
800
  } else {
799
- p->pattern = new(std::nothrow) RE2(StringValuePtr(pattern));
801
+ p->pattern = new(std::nothrow) RE2(RSTRING_PTR(pattern));
800
802
  }
801
803
 
802
804
  if (p->pattern == 0) {
@@ -1285,10 +1287,10 @@ static VALUE re2_regexp_match(int argc, VALUE *argv, const VALUE self) {
1285
1287
 
1286
1288
  if (n == 0) {
1287
1289
  #ifdef HAVE_ENDPOS_ARGUMENT
1288
- bool matched = p->pattern->Match(StringValuePtr(text), 0,
1290
+ bool matched = p->pattern->Match(RSTRING_PTR(text), 0,
1289
1291
  RSTRING_LEN(text), RE2::UNANCHORED, 0, 0);
1290
1292
  #else
1291
- bool matched = p->pattern->Match(StringValuePtr(text), 0, RE2::UNANCHORED,
1293
+ bool matched = p->pattern->Match(RSTRING_PTR(text), 0, RE2::UNANCHORED,
1292
1294
  0, 0);
1293
1295
  #endif
1294
1296
  return BOOL2RUBY(matched);
@@ -1311,10 +1313,10 @@ static VALUE re2_regexp_match(int argc, VALUE *argv, const VALUE self) {
1311
1313
  m->number_of_matches = n;
1312
1314
 
1313
1315
  #ifdef HAVE_ENDPOS_ARGUMENT
1314
- bool matched = p->pattern->Match(StringValuePtr(m->text), 0,
1316
+ bool matched = p->pattern->Match(RSTRING_PTR(m->text), 0,
1315
1317
  RSTRING_LEN(m->text), RE2::UNANCHORED, m->matches, n);
1316
1318
  #else
1317
- bool matched = p->pattern->Match(StringValuePtr(m->text), 0,
1319
+ bool matched = p->pattern->Match(RSTRING_PTR(m->text), 0,
1318
1320
  RE2::UNANCHORED, m->matches, n);
1319
1321
  #endif
1320
1322
  if (matched) {
@@ -1344,6 +1346,9 @@ static VALUE re2_regexp_match_p(const VALUE self, VALUE text) {
1344
1346
  * c = RE2::Regexp.new('(\w+)').scan("Foo bar baz")
1345
1347
  */
1346
1348
  static VALUE re2_regexp_scan(const VALUE self, VALUE text) {
1349
+ /* Ensure text is a string. */
1350
+ StringValue(text);
1351
+
1347
1352
  re2_pattern *p;
1348
1353
  re2_scanner *c;
1349
1354
 
@@ -1351,7 +1356,7 @@ static VALUE re2_regexp_scan(const VALUE self, VALUE text) {
1351
1356
  VALUE scanner = rb_class_new_instance(0, 0, re2_cScanner);
1352
1357
  Data_Get_Struct(scanner, re2_scanner, c);
1353
1358
 
1354
- c->input = new(std::nothrow) re2::StringPiece(StringValuePtr(text));
1359
+ c->input = new(std::nothrow) re2::StringPiece(RSTRING_PTR(text));
1355
1360
  c->regexp = self;
1356
1361
  c->text = text;
1357
1362
 
@@ -1383,9 +1388,11 @@ static VALUE re2_regexp_scan(const VALUE self, VALUE text) {
1383
1388
  * re2 = RE2::Regexp.new("hel+o")
1384
1389
  * RE2.Replace("hello there", re2, "yo") #=> "yo there"
1385
1390
  */
1386
- static VALUE re2_Replace(VALUE self, VALUE str, VALUE pattern,
1391
+ static VALUE re2_Replace(VALUE, VALUE str, VALUE pattern,
1387
1392
  VALUE rewrite) {
1388
- UNUSED(self);
1393
+ /* Ensure rewrite is a string. */
1394
+ StringValue(rewrite);
1395
+
1389
1396
  re2_pattern *p;
1390
1397
 
1391
1398
  /* Take a copy of str so it can be modified in-place by
@@ -1396,13 +1403,15 @@ static VALUE re2_Replace(VALUE self, VALUE str, VALUE pattern,
1396
1403
  /* Do the replacement. */
1397
1404
  if (rb_obj_is_kind_of(pattern, re2_cRegexp)) {
1398
1405
  Data_Get_Struct(pattern, re2_pattern, p);
1399
- RE2::Replace(&str_as_string, *p->pattern, StringValuePtr(rewrite));
1406
+ RE2::Replace(&str_as_string, *p->pattern, RSTRING_PTR(rewrite));
1400
1407
 
1401
1408
  return encoded_str_new(str_as_string.data(), str_as_string.size(),
1402
1409
  p->pattern->options().encoding());
1403
1410
  } else {
1404
- RE2::Replace(&str_as_string, StringValuePtr(pattern),
1405
- StringValuePtr(rewrite));
1411
+ /* Ensure pattern is a string. */
1412
+ StringValue(pattern);
1413
+
1414
+ RE2::Replace(&str_as_string, RSTRING_PTR(pattern), RSTRING_PTR(rewrite));
1406
1415
 
1407
1416
  return encoded_str_new(str_as_string.data(), str_as_string.size(), RE2::Options::EncodingUTF8);
1408
1417
  }
@@ -1424,9 +1433,10 @@ static VALUE re2_Replace(VALUE self, VALUE str, VALUE pattern,
1424
1433
  * RE2.GlobalReplace("whoops-doops", re2, "e") #=> "wheps-deps"
1425
1434
  * RE2.GlobalReplace("hello there", "e", "i") #=> "hillo thiri"
1426
1435
  */
1427
- static VALUE re2_GlobalReplace(VALUE self, VALUE str, VALUE pattern,
1436
+ static VALUE re2_GlobalReplace(VALUE, VALUE str, VALUE pattern,
1428
1437
  VALUE rewrite) {
1429
- UNUSED(self);
1438
+ /* Ensure rewrite is a string. */
1439
+ StringValue(rewrite);
1430
1440
 
1431
1441
  /* Take a copy of str so it can be modified in-place by
1432
1442
  * RE2::GlobalReplace.
@@ -1437,13 +1447,16 @@ static VALUE re2_GlobalReplace(VALUE self, VALUE str, VALUE pattern,
1437
1447
  /* Do the replacement. */
1438
1448
  if (rb_obj_is_kind_of(pattern, re2_cRegexp)) {
1439
1449
  Data_Get_Struct(pattern, re2_pattern, p);
1440
- RE2::GlobalReplace(&str_as_string, *p->pattern, StringValuePtr(rewrite));
1450
+ RE2::GlobalReplace(&str_as_string, *p->pattern, RSTRING_PTR(rewrite));
1441
1451
 
1442
1452
  return encoded_str_new(str_as_string.data(), str_as_string.size(),
1443
1453
  p->pattern->options().encoding());
1444
1454
  } else {
1445
- RE2::GlobalReplace(&str_as_string, StringValuePtr(pattern),
1446
- StringValuePtr(rewrite));
1455
+ /* Ensure pattern is a string. */
1456
+ StringValue(pattern);
1457
+
1458
+ RE2::GlobalReplace(&str_as_string, RSTRING_PTR(pattern),
1459
+ RSTRING_PTR(rewrite));
1447
1460
 
1448
1461
  return encoded_str_new(str_as_string.data(), str_as_string.size(), RE2::Options::EncodingUTF8);
1449
1462
  }
@@ -1459,9 +1472,10 @@ static VALUE re2_GlobalReplace(VALUE self, VALUE str, VALUE pattern,
1459
1472
  * @example
1460
1473
  * RE2::Regexp.escape("1.5-2.0?") #=> "1\.5\-2\.0\?"
1461
1474
  */
1462
- static VALUE re2_QuoteMeta(VALUE self, VALUE unquoted) {
1463
- UNUSED(self);
1464
- std::string quoted_string = RE2::QuoteMeta(StringValuePtr(unquoted));
1475
+ static VALUE re2_QuoteMeta(VALUE, VALUE unquoted) {
1476
+ StringValue(unquoted);
1477
+
1478
+ std::string quoted_string = RE2::QuoteMeta(RSTRING_PTR(unquoted));
1465
1479
 
1466
1480
  return rb_str_new(quoted_string.data(), quoted_string.size());
1467
1481
  }
@@ -1524,15 +1538,12 @@ static VALUE re2_set_allocate(VALUE klass) {
1524
1538
  static VALUE re2_set_initialize(int argc, VALUE *argv, VALUE self) {
1525
1539
  VALUE anchor, options;
1526
1540
  re2_set *s;
1527
- RE2::Anchor re2_anchor = RE2::UNANCHORED;
1528
- RE2::Options re2_options;
1529
1541
 
1530
1542
  rb_scan_args(argc, argv, "02", &anchor, &options);
1531
1543
  Data_Get_Struct(self, re2_set, s);
1532
1544
 
1533
- if (RTEST(options)) {
1534
- parse_re2_options(&re2_options, options);
1535
- }
1545
+ RE2::Anchor re2_anchor = RE2::UNANCHORED;
1546
+
1536
1547
  if (!NIL_P(anchor)) {
1537
1548
  Check_Type(anchor, T_SYMBOL);
1538
1549
  ID id_anchor = SYM2ID(anchor);
@@ -1547,6 +1558,12 @@ static VALUE re2_set_initialize(int argc, VALUE *argv, VALUE self) {
1547
1558
  }
1548
1559
  }
1549
1560
 
1561
+ RE2::Options re2_options;
1562
+
1563
+ if (RTEST(options)) {
1564
+ parse_re2_options(&re2_options, options);
1565
+ }
1566
+
1550
1567
  s->set = new(std::nothrow) RE2::Set(re2_options, re2_anchor);
1551
1568
  if (s->set == 0) {
1552
1569
  rb_raise(rb_eNoMemError, "not enough memory to allocate RE2::Set object");
@@ -1569,14 +1586,24 @@ static VALUE re2_set_initialize(int argc, VALUE *argv, VALUE self) {
1569
1586
  */
1570
1587
  static VALUE re2_set_add(VALUE self, VALUE pattern) {
1571
1588
  StringValue(pattern);
1572
- re2::StringPiece regex(RSTRING_PTR(pattern), RSTRING_LEN(pattern));
1573
- std::string err;
1589
+
1574
1590
  re2_set *s;
1575
1591
  Data_Get_Struct(self, re2_set, s);
1576
1592
 
1577
- int index = s->set->Add(regex, &err);
1593
+ /* To prevent the memory of the err string leaking when we call rb_raise,
1594
+ * take a copy of it and let it go out of scope.
1595
+ */
1596
+ char msg[100];
1597
+ int index;
1598
+
1599
+ {
1600
+ std::string err;
1601
+ index = s->set->Add(RSTRING_PTR(pattern), &err);
1602
+ strlcpy(msg, err.c_str(), sizeof(msg));
1603
+ }
1604
+
1578
1605
  if (index < 0) {
1579
- rb_raise(rb_eArgError, "str rejected by RE2::Set->Add(): %s", err.c_str());
1606
+ rb_raise(rb_eArgError, "str rejected by RE2::Set->Add(): %s", msg);
1580
1607
  }
1581
1608
 
1582
1609
  return INT2FIX(index);
@@ -1606,8 +1633,7 @@ static VALUE re2_set_compile(VALUE self) {
1606
1633
  *
1607
1634
  * @return [Bool] whether the underlying re2 outputs error information from Set matches
1608
1635
  */
1609
- static VALUE re2_set_match_raises_errors_p(VALUE self) {
1610
- UNUSED(self);
1636
+ static VALUE re2_set_match_raises_errors_p(VALUE) {
1611
1637
  #ifdef HAVE_ERROR_INFO_ARGUMENT
1612
1638
  return Qtrue;
1613
1639
  #else
@@ -1661,7 +1687,6 @@ static VALUE re2_set_match(int argc, VALUE *argv, const VALUE self) {
1661
1687
  rb_scan_args(argc, argv, "11", &str, &options);
1662
1688
 
1663
1689
  StringValue(str);
1664
- re2::StringPiece data(RSTRING_PTR(str), RSTRING_LEN(str));
1665
1690
  re2_set *s;
1666
1691
  Data_Get_Struct(self, re2_set, s);
1667
1692
 
@@ -1679,7 +1704,7 @@ static VALUE re2_set_match(int argc, VALUE *argv, const VALUE self) {
1679
1704
  if (raise_exception) {
1680
1705
  #ifdef HAVE_ERROR_INFO_ARGUMENT
1681
1706
  RE2::Set::ErrorInfo e;
1682
- bool match_failed = !s->set->Match(data, &v, &e);
1707
+ bool match_failed = !s->set->Match(RSTRING_PTR(str), &v, &e);
1683
1708
  VALUE result = rb_ary_new2(v.size());
1684
1709
 
1685
1710
  if (match_failed) {
@@ -1706,7 +1731,7 @@ static VALUE re2_set_match(int argc, VALUE *argv, const VALUE self) {
1706
1731
  rb_raise(re2_eSetUnsupportedError, "current version of RE2::Set::Match() does not output error information, :exception option can only be set to false");
1707
1732
  #endif
1708
1733
  } else {
1709
- bool matched = s->set->Match(data, &v);
1734
+ bool matched = s->set->Match(RSTRING_PTR(str), &v);
1710
1735
  VALUE result = rb_ary_new2(v.size());
1711
1736
 
1712
1737
  if (matched) {
@@ -1719,12 +1744,7 @@ static VALUE re2_set_match(int argc, VALUE *argv, const VALUE self) {
1719
1744
  }
1720
1745
  }
1721
1746
 
1722
- /* Forward declare Init_re2 to be called by C code but define it separately so
1723
- * that YARD can parse it.
1724
- */
1725
- extern "C" void Init_re2(void);
1726
-
1727
- void Init_re2(void) {
1747
+ extern "C" void Init_re2(void) {
1728
1748
  re2_mRE2 = rb_define_module("RE2");
1729
1749
  re2_cRegexp = rb_define_class_under(re2_mRE2, "Regexp", rb_cObject);
1730
1750
  re2_cMatchData = rb_define_class_under(re2_mRE2, "MatchData", rb_cObject);
data/ext/re2/recipes.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  PACKAGE_ROOT_DIR = File.expand_path('../..', __dir__)
2
- REQUIRED_MINI_PORTILE_VERSION = '~> 2.8.4' # keep this version in sync with the one in the gemspec
2
+ REQUIRED_MINI_PORTILE_VERSION = '~> 2.8.5' # keep this version in sync with the one in the gemspec
3
3
 
4
4
  def build_recipe(name, version)
5
5
  require 'rubygems'
@@ -10,7 +10,7 @@ def build_recipe(name, version)
10
10
  recipe.target = File.join(PACKAGE_ROOT_DIR, 'ports')
11
11
  recipe.configure_options += [
12
12
  # abseil needs a C++14 compiler
13
- '-DCMAKE_CXX_STANDARD=17',
13
+ '-DCMAKE_CXX_STANDARD=14',
14
14
  # needed for building the C extension shared library with -fPIC
15
15
  '-DCMAKE_POSITION_INDEPENDENT_CODE=ON',
16
16
  # ensures pkg-config and installed libraries will be in lib, not lib64
data/lib/2.6/re2.so CHANGED
Binary file
data/lib/2.7/re2.so CHANGED
Binary file
data/lib/3.0/re2.so CHANGED
Binary file
data/lib/3.1/re2.so CHANGED
Binary file
data/lib/3.2/re2.so CHANGED
Binary file
data/lib/re2/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RE2
4
- VERSION = "2.1.2"
4
+ VERSION = "2.2.0"
5
5
  end
data/re2.gemspec CHANGED
@@ -40,5 +40,5 @@ Gem::Specification.new do |s|
40
40
  s.add_development_dependency("rake-compiler", "~> 1.2.1")
41
41
  s.add_development_dependency("rake-compiler-dock", "~> 1.3.0")
42
42
  s.add_development_dependency("rspec", "~> 3.2")
43
- s.add_runtime_dependency("mini_portile2", "~> 2.8.4") # keep version in sync with extconf.rb
43
+ s.add_runtime_dependency("mini_portile2", "~> 2.8.5") # keep version in sync with extconf.rb
44
44
  end
data/spec/kernel_spec.rb CHANGED
@@ -9,5 +9,21 @@ RSpec.describe Kernel do
9
9
 
10
10
  expect(re).not_to be_case_sensitive
11
11
  end
12
+
13
+ it "raises an error if given an inappropriate type" do
14
+ expect { RE2(nil) }.to raise_error(TypeError)
15
+ end
16
+
17
+ it "allows invalid patterns to be created" do
18
+ re = RE2('???', :log_errors => false)
19
+
20
+ expect(re).to be_a(RE2::Regexp)
21
+ end
22
+
23
+ it "supports passing something that can be coerced to a String as input" do
24
+ re = RE2(StringLike.new('w(o)(o)'))
25
+
26
+ expect(re).to be_a(RE2::Regexp)
27
+ end
12
28
  end
13
29
  end
@@ -18,9 +18,15 @@ RSpec.describe RE2::Regexp do
18
18
  re = RE2::Regexp.new('???', :log_errors => false)
19
19
  expect(re).to be_a(RE2::Regexp)
20
20
  end
21
+
22
+ it "supports passing something that can be coerced to a String as input" do
23
+ re = RE2::Regexp.new(StringLike.new('w(o)(o)'))
24
+
25
+ expect(re).to be_a(RE2::Regexp)
26
+ end
21
27
  end
22
28
 
23
- describe "#compile" do
29
+ describe ".compile" do
24
30
  it "returns an instance given only a pattern" do
25
31
  re = RE2::Regexp.compile('woo')
26
32
  expect(re).to be_a(RE2::Regexp)
@@ -31,10 +37,20 @@ RSpec.describe RE2::Regexp do
31
37
  expect(re).to be_a(RE2::Regexp)
32
38
  end
33
39
 
40
+ it "raises an error if given an inappropriate type" do
41
+ expect { RE2::Regexp.compile(nil) }.to raise_error(TypeError)
42
+ end
43
+
34
44
  it "allows invalid patterns to be created" do
35
45
  re = RE2::Regexp.compile('???', :log_errors => false)
36
46
  expect(re).to be_a(RE2::Regexp)
37
47
  end
48
+
49
+ it "supports passing something that can be coerced to a String as input" do
50
+ re = RE2::Regexp.compile(StringLike.new('w(o)(o)'))
51
+
52
+ expect(re).to be_a(RE2::Regexp)
53
+ end
38
54
  end
39
55
 
40
56
  describe "#options" do
@@ -59,7 +75,7 @@ RSpec.describe RE2::Regexp do
59
75
 
60
76
  it "is populated with overridden options when specified" do
61
77
  options = RE2::Regexp.new('woo', :case_sensitive => false).options
62
- expect(options[:case_sensitive]).to eq(false)
78
+ expect(options).to include(:case_sensitive => false)
63
79
  end
64
80
  end
65
81
 
@@ -82,7 +98,7 @@ RSpec.describe RE2::Regexp do
82
98
  expect(error_arg).to be_nil
83
99
  end
84
100
 
85
- it "returns the offending portin of the regexp if there is an error" do
101
+ it "returns the offending portion of the regexp if there is an error" do
86
102
  error_arg = RE2::Regexp.new('wo(o', :log_errors => false).error_arg
87
103
  expect(error_arg).to eq("wo(o")
88
104
  end
data/spec/re2/set_spec.rb CHANGED
@@ -40,6 +40,13 @@ RSpec.describe RE2::Set do
40
40
  "anchor should be one of: :unanchored, :anchor_start, :anchor_both"
41
41
  )
42
42
  end
43
+
44
+ it "raises an error if given an invalid anchor and options" do
45
+ expect { RE2::Set.new(:not_a_valid_anchor, :case_sensitive => false) }.to raise_error(
46
+ ArgumentError,
47
+ "anchor should be one of: :unanchored, :anchor_start, :anchor_both"
48
+ )
49
+ end
43
50
  end
44
51
 
45
52
  describe "#add" do
@@ -54,7 +61,13 @@ RSpec.describe RE2::Set do
54
61
  it "rejects invalid patterns when added" do
55
62
  set = RE2::Set.new(:unanchored, :log_errors => false)
56
63
 
57
- expect { set.add("???") }.to raise_error(ArgumentError, /str rejected by RE2::Set->Add()/)
64
+ expect { set.add("???") }.to raise_error(ArgumentError, /str rejected by RE2::Set->Add\(\)/)
65
+ end
66
+
67
+ it "truncates error messages to 100 characters" do
68
+ set = RE2::Set.new(:unanchored, :log_errors => false)
69
+
70
+ expect { set.add("(?P<#{'o' * 200}") }.to raise_error(ArgumentError, "str rejected by RE2::Set->Add(): invalid named capture group: (?P<oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo")
58
71
  end
59
72
 
60
73
  it "raises an error if called after #compile" do
data/spec/re2_spec.rb CHANGED
@@ -12,11 +12,12 @@ RSpec.describe RE2 do
12
12
  expect(RE2.Replace("Good morning", "(?i)gOOD MORNING", "hi")).to eq("hi")
13
13
  end
14
14
 
15
- it "does not perform replacements in-place" do
15
+ it "does not perform replacements in-place", :aggregate_failures do
16
16
  name = "Robert"
17
17
  replacement = RE2.Replace(name, "R", "Cr")
18
18
 
19
- expect(name).not_to equal(replacement)
19
+ expect(name).to eq("Robert")
20
+ expect(replacement).to eq("Crobert")
20
21
  end
21
22
 
22
23
  it "supports passing an RE2::Regexp as the pattern" do
@@ -89,11 +90,12 @@ RSpec.describe RE2 do
89
90
  expect(RE2.GlobalReplace("Robert", "(?i)r", "w")).to eq("wobewt")
90
91
  end
91
92
 
92
- it "does not perform replacement in-place" do
93
+ it "does not perform replacement in-place", :aggregate_failures do
93
94
  name = "Robert"
94
95
  replacement = RE2.GlobalReplace(name, "(?i)R", "w")
95
96
 
96
- expect(name).not_to equal(replacement)
97
+ expect(name).to eq("Robert")
98
+ expect(replacement).to eq("wobewt")
97
99
  end
98
100
 
99
101
  it "supports passing an RE2::Regexp as the pattern" 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.1.2
4
+ version: 2.2.0
5
5
  platform: x86_64-linux
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: 2023-09-20 00:00:00.000000000 Z
12
+ date: 2023-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler