re2 2.20.0-arm64-darwin → 2.22.0-arm64-darwin
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/README.md +5 -3
- data/Rakefile +1 -1
- data/dependencies.yml +2 -2
- data/ext/re2/re2.cc +48 -41
- data/lib/3.1/re2.bundle +0 -0
- data/lib/3.2/re2.bundle +0 -0
- data/lib/3.3/re2.bundle +0 -0
- data/lib/3.4/re2.bundle +0 -0
- data/lib/re2/version.rb +1 -1
- data/spec/re2/match_data_spec.rb +21 -0
- data/spec/re2/regexp_spec.rb +17 -0
- data/spec/re2/scanner_spec.rb +50 -1
- data/spec/re2/set_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a3c9a376891ca658c808ff093720cd2f78872dc03247a5fd65093982136a90a5
|
|
4
|
+
data.tar.gz: 5b0c7326f37ba5f02be27c0215b986fc007d832e1ad1d313a07f2c495d90e186
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a406d71e277f509396eaec77798e0837b6f9af5d660c432d4ff367a5a42c2af96891feac35304573aaa94a195361f9fa9137621af79eaeb6e2e56beaf6c31512
|
|
7
|
+
data.tar.gz: 205f3f81aa5fad63990bc21a0d8e7216c837faf4668370652887ec48d22941cdca66698bf3ad8c21d389a665d57f1e2f1507a752216031df1d3efefa9f1f3585
|
data/README.md
CHANGED
|
@@ -6,8 +6,8 @@ Python".
|
|
|
6
6
|
|
|
7
7
|
[](https://github.com/mudge/re2/actions)
|
|
8
8
|
|
|
9
|
-
**Current version:** 2.
|
|
10
|
-
**Bundled RE2 version:** libre2.11 (2025-
|
|
9
|
+
**Current version:** 2.22.0
|
|
10
|
+
**Bundled RE2 version:** libre2.11 (2025-11-05)
|
|
11
11
|
|
|
12
12
|
```ruby
|
|
13
13
|
RE2('h.*o').full_match?("hello") #=> true
|
|
@@ -264,7 +264,7 @@ This gem requires the following to run:
|
|
|
264
264
|
|
|
265
265
|
It supports the following RE2 ABI versions:
|
|
266
266
|
|
|
267
|
-
* libre2.0 (prior to release 2020-03-02) to libre2.11 (2023-07-01 to 2025-
|
|
267
|
+
* libre2.0 (prior to release 2020-03-02) to libre2.11 (2023-07-01 to 2025-11-05)
|
|
268
268
|
|
|
269
269
|
### Native gems
|
|
270
270
|
|
|
@@ -378,6 +378,8 @@ Alternatively, you can set the `RE2_USE_SYSTEM_LIBRARIES` environment variable i
|
|
|
378
378
|
improvements in 2.4.0.
|
|
379
379
|
* Thanks to [Manuel Jacob](https://github.com/manueljacob) for reporting a bug
|
|
380
380
|
when passing strings with null bytes.
|
|
381
|
+
* Thanks to [Maciej Gajewski](https://github.com/konieczkow) for helping
|
|
382
|
+
confirm issues with GC compaction and mutable strings.
|
|
381
383
|
|
|
382
384
|
## Contact
|
|
383
385
|
|
data/Rakefile
CHANGED
|
@@ -76,7 +76,7 @@ namespace :gem do
|
|
|
76
76
|
sudo apt-get install -y cmake=3.22.2-0kitware1ubuntu20.04.1 cmake-data=3.22.2-0kitware1ubuntu20.04.1 &&
|
|
77
77
|
rbenv shell 3.1.6 &&
|
|
78
78
|
gem install bundler --no-document &&
|
|
79
|
-
bundle &&
|
|
79
|
+
bundle install &&
|
|
80
80
|
bundle exec rake native:#{platform} pkg/#{re2_gemspec.full_name}-#{Gem::Platform.new(platform)}.gem PATH="/usr/local/bin:$PATH"
|
|
81
81
|
SCRIPT
|
|
82
82
|
end
|
data/dependencies.yml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
libre2:
|
|
3
|
-
version: '2025-
|
|
4
|
-
sha256:
|
|
3
|
+
version: '2025-11-05'
|
|
4
|
+
sha256: 87f6029d2f6de8aa023654240a03ada90e876ce9a4676e258dd01ea4c26ffd67
|
|
5
5
|
abseil:
|
|
6
6
|
version: '20250814.1'
|
|
7
7
|
sha256: 1692f77d1739bacf3f94337188b78583cf09bab7e420d2dc6c5605a4f86785a1
|
data/ext/re2/re2.cc
CHANGED
|
@@ -128,13 +128,12 @@ static void parse_re2_options(RE2::Options* re2_options, const VALUE options) {
|
|
|
128
128
|
static void re2_matchdata_mark(void *ptr) {
|
|
129
129
|
re2_matchdata *m = reinterpret_cast<re2_matchdata *>(ptr);
|
|
130
130
|
rb_gc_mark_movable(m->regexp);
|
|
131
|
-
|
|
131
|
+
rb_gc_mark(m->text);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
static void re2_matchdata_compact(void *ptr) {
|
|
135
135
|
re2_matchdata *m = reinterpret_cast<re2_matchdata *>(ptr);
|
|
136
136
|
m->regexp = rb_gc_location(m->regexp);
|
|
137
|
-
m->text = rb_gc_location(m->text);
|
|
138
137
|
}
|
|
139
138
|
|
|
140
139
|
static void re2_matchdata_free(void *ptr) {
|
|
@@ -173,13 +172,12 @@ static const rb_data_type_t re2_matchdata_data_type = {
|
|
|
173
172
|
static void re2_scanner_mark(void *ptr) {
|
|
174
173
|
re2_scanner *s = reinterpret_cast<re2_scanner *>(ptr);
|
|
175
174
|
rb_gc_mark_movable(s->regexp);
|
|
176
|
-
|
|
175
|
+
rb_gc_mark(s->text);
|
|
177
176
|
}
|
|
178
177
|
|
|
179
178
|
static void re2_scanner_compact(void *ptr) {
|
|
180
179
|
re2_scanner *s = reinterpret_cast<re2_scanner *>(ptr);
|
|
181
180
|
s->regexp = rb_gc_location(s->regexp);
|
|
182
|
-
s->text = rb_gc_location(s->text);
|
|
183
181
|
}
|
|
184
182
|
|
|
185
183
|
static void re2_scanner_free(void *ptr) {
|
|
@@ -278,10 +276,12 @@ static VALUE re2_matchdata_string(const VALUE self) {
|
|
|
278
276
|
}
|
|
279
277
|
|
|
280
278
|
/*
|
|
281
|
-
* Returns the text supplied when incrementally matching with
|
|
279
|
+
* Returns a frozen copy of the text supplied when incrementally matching with
|
|
282
280
|
* {RE2::Regexp#scan}.
|
|
283
281
|
*
|
|
284
|
-
*
|
|
282
|
+
* If the text was already a frozen string, returns the original.
|
|
283
|
+
*
|
|
284
|
+
* @return [String] a frozen string with the text passed to {RE2::Regexp#scan}
|
|
285
285
|
* @example
|
|
286
286
|
* c = RE2::Regexp.new('(\d+)').scan("foo")
|
|
287
287
|
* c.string #=> "foo"
|
|
@@ -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 (
|
|
416
|
-
id =
|
|
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) || !
|
|
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(
|
|
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 (
|
|
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
|
-
|
|
1522
|
-
|
|
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
|
-
|
|
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(
|
|
1540
|
-
startpos, endpos, anchor,
|
|
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(
|
|
1544
|
-
startpos, anchor,
|
|
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
|
}
|
|
@@ -1614,10 +1619,14 @@ static VALUE re2_regexp_scan(const VALUE self, VALUE text) {
|
|
|
1614
1619
|
VALUE scanner = rb_class_new_instance(0, 0, re2_cScanner);
|
|
1615
1620
|
TypedData_Get_Struct(scanner, re2_scanner, &re2_scanner_data_type, c);
|
|
1616
1621
|
|
|
1617
|
-
c->input = new(std::nothrow) re2::StringPiece(
|
|
1618
|
-
RSTRING_PTR(text), RSTRING_LEN(text));
|
|
1619
1622
|
RB_OBJ_WRITE(scanner, &c->regexp, self);
|
|
1620
|
-
RB_OBJ_WRITE(scanner, &c->text, text);
|
|
1623
|
+
RB_OBJ_WRITE(scanner, &c->text, rb_str_new_frozen(text));
|
|
1624
|
+
c->input = new(std::nothrow) re2::StringPiece(
|
|
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
|
+
}
|
|
1621
1630
|
|
|
1622
1631
|
if (p->pattern->ok()) {
|
|
1623
1632
|
c->number_of_capturing_groups = p->pattern->NumberOfCapturingGroups();
|
|
@@ -1913,21 +1922,19 @@ static VALUE re2_set_add(VALUE self, VALUE pattern) {
|
|
|
1913
1922
|
re2_set *s;
|
|
1914
1923
|
TypedData_Get_Struct(self, re2_set, &re2_set_data_type, s);
|
|
1915
1924
|
|
|
1916
|
-
/* To prevent the memory of the err string leaking when we call rb_raise,
|
|
1917
|
-
* take a copy of it and let it go out of scope.
|
|
1918
|
-
*/
|
|
1919
|
-
char msg[100];
|
|
1920
1925
|
int index;
|
|
1926
|
+
VALUE msg;
|
|
1921
1927
|
|
|
1922
1928
|
{
|
|
1923
1929
|
std::string err;
|
|
1924
1930
|
index = s->set->Add(
|
|
1925
1931
|
re2::StringPiece(RSTRING_PTR(pattern), RSTRING_LEN(pattern)), &err);
|
|
1926
|
-
|
|
1932
|
+
msg = rb_str_new(err.data(), err.size());
|
|
1927
1933
|
}
|
|
1928
1934
|
|
|
1929
1935
|
if (index < 0) {
|
|
1930
|
-
rb_raise(rb_eArgError,
|
|
1936
|
+
rb_raise(rb_eArgError,
|
|
1937
|
+
"str rejected by RE2::Set->Add(): %s", RSTRING_PTR(msg));
|
|
1931
1938
|
}
|
|
1932
1939
|
|
|
1933
1940
|
return INT2FIX(index);
|
data/lib/3.1/re2.bundle
CHANGED
|
Binary file
|
data/lib/3.2/re2.bundle
CHANGED
|
Binary file
|
data/lib/3.3/re2.bundle
CHANGED
|
Binary file
|
data/lib/3.4/re2.bundle
CHANGED
|
Binary file
|
data/lib/re2/version.rb
CHANGED
data/spec/re2/match_data_spec.rb
CHANGED
|
@@ -133,6 +133,13 @@ RSpec.describe RE2::MatchData do
|
|
|
133
133
|
expect(md["name"].encoding.name).to eq("ISO-8859-1")
|
|
134
134
|
expect(md[:name].encoding.name).to eq("ISO-8859-1")
|
|
135
135
|
end
|
|
136
|
+
|
|
137
|
+
it "supports GC compaction" do
|
|
138
|
+
md = RE2::Regexp.new('(wo{2})').match('woohoo' * 5)
|
|
139
|
+
GC.compact
|
|
140
|
+
|
|
141
|
+
expect(md[1]).to eq("woo")
|
|
142
|
+
end
|
|
136
143
|
end
|
|
137
144
|
|
|
138
145
|
describe "#string" do
|
|
@@ -287,6 +294,13 @@ RSpec.describe RE2::MatchData do
|
|
|
287
294
|
|
|
288
295
|
expect { md.begin(nil) }.to raise_error(TypeError)
|
|
289
296
|
end
|
|
297
|
+
|
|
298
|
+
it "supports GC compaction" do
|
|
299
|
+
md = RE2::Regexp.new('(wo{2})').match('woohoo' * 5)
|
|
300
|
+
GC.compact
|
|
301
|
+
|
|
302
|
+
expect(md.string[md.begin(0)..-1]).to eq('woohoo' * 5)
|
|
303
|
+
end
|
|
290
304
|
end
|
|
291
305
|
|
|
292
306
|
describe "#end" do
|
|
@@ -349,6 +363,13 @@ RSpec.describe RE2::MatchData do
|
|
|
349
363
|
|
|
350
364
|
expect { md.end(nil) }.to raise_error(TypeError)
|
|
351
365
|
end
|
|
366
|
+
|
|
367
|
+
it "supports GC compaction" do
|
|
368
|
+
md = RE2::Regexp.new('(wo{2})').match('woohoo' * 5)
|
|
369
|
+
GC.compact
|
|
370
|
+
|
|
371
|
+
expect(md.string[0...md.end(0)]).to eq('woo')
|
|
372
|
+
end
|
|
352
373
|
end
|
|
353
374
|
|
|
354
375
|
describe "#deconstruct" do
|
data/spec/re2/regexp_spec.rb
CHANGED
|
@@ -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/scanner_spec.rb
CHANGED
|
@@ -11,7 +11,39 @@ RSpec.describe RE2::Scanner do
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
describe "#string" do
|
|
14
|
-
it "returns the
|
|
14
|
+
it "returns the text for the scanner" do
|
|
15
|
+
re = RE2::Regexp.new('(\w+)')
|
|
16
|
+
text = "It is a truth"
|
|
17
|
+
scanner = re.scan(text)
|
|
18
|
+
|
|
19
|
+
expect(scanner.string).to eq("It is a truth")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "returns a frozen string" do
|
|
23
|
+
re = RE2::Regexp.new('(\w+)')
|
|
24
|
+
text = "It is a truth"
|
|
25
|
+
scanner = re.scan(text)
|
|
26
|
+
|
|
27
|
+
expect(scanner.string).to be_frozen
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "freezes unfrozen strings" do
|
|
31
|
+
re = RE2::Regexp.new('(\w+)')
|
|
32
|
+
text = +"It is a truth"
|
|
33
|
+
scanner = re.scan(text)
|
|
34
|
+
|
|
35
|
+
expect(scanner.string).to be_frozen
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "copies unfrozen strings" do
|
|
39
|
+
re = RE2::Regexp.new('(\w+)')
|
|
40
|
+
text = +"It is a truth"
|
|
41
|
+
scanner = re.scan(text)
|
|
42
|
+
|
|
43
|
+
expect(scanner.string).to_not equal(text)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "does not copy the string if it was already frozen" do
|
|
15
47
|
re = RE2::Regexp.new('(\w+)')
|
|
16
48
|
text = "It is a truth"
|
|
17
49
|
scanner = re.scan(text)
|
|
@@ -162,6 +194,23 @@ RSpec.describe RE2::Scanner do
|
|
|
162
194
|
expect(scanner.scan).to eq(["world"])
|
|
163
195
|
expect(scanner.scan).to be_nil
|
|
164
196
|
end
|
|
197
|
+
|
|
198
|
+
it "supports GC compaction" do
|
|
199
|
+
r = RE2::Regexp.new('(\w+)')
|
|
200
|
+
scanner = r.scan("Hello world" * 2)
|
|
201
|
+
GC.compact
|
|
202
|
+
|
|
203
|
+
expect(scanner.scan).to eq(["Hello"])
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
it "works even if the original input is mutated" do
|
|
207
|
+
r = RE2::Regexp.new('(\w+)')
|
|
208
|
+
text = +"It is a truth universally acknowledged"
|
|
209
|
+
scanner = r.scan(text)
|
|
210
|
+
text.upcase!
|
|
211
|
+
|
|
212
|
+
expect(scanner.scan).to eq(["It"])
|
|
213
|
+
end
|
|
165
214
|
end
|
|
166
215
|
|
|
167
216
|
it "is enumerable" do
|
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 "
|
|
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<
|
|
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.
|
|
4
|
+
version: 2.22.0
|
|
5
5
|
platform: arm64-darwin
|
|
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-
|
|
12
|
+
date: 2025-11-30 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rake-compiler
|