re2 1.10.1 → 1.10.5
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.
- package/.travis.yml +1 -0
- package/README.md +7 -4
- package/lib/exec.cc +8 -0
- package/package.json +2 -1
- package/re2.d.ts +5 -0
- package/tests/test_exec.js +1 -0
- package/vendor/re2/bitstate.cc +5 -1
- package/vendor/re2/compile.cc +1 -1
- package/vendor/re2/dfa.cc +8 -11
- package/vendor/re2/nfa.cc +33 -16
- package/vendor/re2/onepass.cc +4 -4
- package/vendor/re2/parse.cc +32 -32
- package/vendor/{util → re2}/pod_array.h +3 -3
- package/vendor/re2/prefilter_tree.h +1 -1
- package/vendor/re2/prog.h +3 -3
- package/vendor/re2/re2.cc +3 -3
- package/vendor/re2/set.cc +2 -2
- package/vendor/re2/simplify.cc +1 -1
- package/vendor/{util → re2}/sparse_array.h +4 -4
- package/vendor/{util → re2}/sparse_set.h +4 -4
- package/vendor/re2/testing/backtrack.cc +4 -0
- package/vendor/re2/testing/dfa_test.cc +12 -10
- package/vendor/re2/testing/dump.cc +4 -10
- package/vendor/re2/testing/exhaustive1_test.cc +2 -7
- package/vendor/re2/testing/exhaustive2_test.cc +0 -1
- package/vendor/re2/testing/exhaustive_tester.cc +11 -8
- package/vendor/re2/testing/random_test.cc +9 -7
- package/vendor/re2/testing/regexp_benchmark.cc +435 -404
- package/vendor/re2/testing/regexp_generator.cc +1 -1
- package/vendor/re2/testing/tester.cc +19 -14
- package/vendor/re2/walker-inl.h +1 -1
- package/vendor/util/benchmark.cc +83 -113
- package/vendor/util/benchmark.h +138 -25
- package/vendor/util/flags.h +8 -11
- package/vendor/util/malloc_counter.h +19 -0
- package/vendor/util/pcre.cc +7 -31
- package/vendor/util/test.cc +4 -1
- package/vendor/util/test.h +4 -12
- package/vendor/util/util.h +8 -0
package/.travis.yml
CHANGED
package/README.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
# node-re2
|
|
2
2
|
|
|
3
|
-
[![Build status][travis-image]][travis-url]
|
|
4
|
-
[![Dependencies][deps-image]][deps-url]
|
|
5
|
-
[![devDependencies][dev-deps-image]][dev-deps-url]
|
|
3
|
+
<!-- [![Build status][travis-image]][travis-url] -->
|
|
6
4
|
[![NPM version][npm-image]][npm-url]
|
|
7
5
|
|
|
8
6
|
[](https://greenkeeper.io/)
|
|
9
|
-
|
|
7
|
+
[![Dependencies][deps-image]][deps-url]
|
|
8
|
+
[![devDependencies][dev-deps-image]][dev-deps-url]
|
|
10
9
|
|
|
11
10
|
This project provides bindings for [RE2](https://github.com/google/re2):
|
|
12
11
|
fast, safe alternative to backtracking regular expression engines written by [Russ Cox](http://swtch.com/~rsc/).
|
|
@@ -353,6 +352,10 @@ Or:
|
|
|
353
352
|
|
|
354
353
|
## Release history
|
|
355
354
|
|
|
355
|
+
- 1.10.5 *Bugfix for optional groups (thx [Josh Yudaken](https://github.com/qix)), the latest version of `re2`.*
|
|
356
|
+
- 1.10.4 *Technical release: even better TypeScript types (thx [Louis Brann](https://github.com/louis-brann)).*
|
|
357
|
+
- 1.10.3 *Technical release: missing reference to TS types (thx [Jamie Magee](https://github.com/JamieMagee)).*
|
|
358
|
+
- 1.10.2 *Technical release: added TypeScript types (thx [Jamie Magee](https://github.com/JamieMagee)).*
|
|
356
359
|
- 1.10.1 *Updated `re2` to the latest version (thx [Jamie Magee](https://github.com/JamieMagee)), dropped Node 6.*
|
|
357
360
|
- 1.10.0 *Added back support for Node 6 and Node 8. Now Node 6-12 is supported.*
|
|
358
361
|
- 1.9.0 *Refreshed dependencies to support Node 12. Only versions 10-12 are supported now (`v8` restrictions). For older versions use `node-re2@1.8`.*
|
package/lib/exec.cc
CHANGED
|
@@ -83,6 +83,10 @@ NAN_METHOD(WrappedRE2::Exec)
|
|
|
83
83
|
{
|
|
84
84
|
Nan::Set(result, i, Nan::CopyBuffer(item.data(), item.size()).ToLocalChecked());
|
|
85
85
|
}
|
|
86
|
+
else
|
|
87
|
+
{
|
|
88
|
+
Nan::Set(result, i, Nan::Undefined());
|
|
89
|
+
}
|
|
86
90
|
}
|
|
87
91
|
Nan::Set(result, Nan::New("index").ToLocalChecked(), Nan::New<v8::Integer>(indexOffset + static_cast<int>(groups[0].data() - str.data)));
|
|
88
92
|
}
|
|
@@ -95,6 +99,10 @@ NAN_METHOD(WrappedRE2::Exec)
|
|
|
95
99
|
{
|
|
96
100
|
Nan::Set(result, i, Nan::New(item.data(), item.size()).ToLocalChecked());
|
|
97
101
|
}
|
|
102
|
+
else
|
|
103
|
+
{
|
|
104
|
+
Nan::Set(result, i, Nan::Undefined());
|
|
105
|
+
}
|
|
98
106
|
}
|
|
99
107
|
Nan::Set(result, Nan::New("index").ToLocalChecked(), Nan::New<v8::Integer>(indexOffset + static_cast<int>(getUtf16Length(str.data + lastIndex, groups[0].data()))));
|
|
100
108
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "re2",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.5",
|
|
4
4
|
"description": "Bindings for RE2: fast, safe alternative to backtracking regular expression engines.",
|
|
5
5
|
"homepage": "http://github.com/uhop/node-re2",
|
|
6
6
|
"bugs": "http://github.com/uhop/node-re2/issues",
|
|
7
7
|
"main": "re2.js",
|
|
8
|
+
"types": "re2.d.ts",
|
|
8
9
|
"directories": {
|
|
9
10
|
"test": "tests"
|
|
10
11
|
},
|
package/re2.d.ts
ADDED
package/tests/test_exec.js
CHANGED
package/vendor/re2/bitstate.cc
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
#include <utility>
|
|
25
25
|
|
|
26
26
|
#include "util/logging.h"
|
|
27
|
-
#include "
|
|
27
|
+
#include "re2/pod_array.h"
|
|
28
28
|
#include "re2/prog.h"
|
|
29
29
|
#include "re2/regexp.h"
|
|
30
30
|
|
|
@@ -342,6 +342,10 @@ bool BitState::Search(const StringPiece& text, const StringPiece& context,
|
|
|
342
342
|
cap_[0] = p;
|
|
343
343
|
if (TrySearch(prog_->start(), p)) // Match must be leftmost; done.
|
|
344
344
|
return true;
|
|
345
|
+
// Avoid invoking undefined behavior (arithmetic on a null pointer)
|
|
346
|
+
// by simply not continuing the loop.
|
|
347
|
+
if (p == NULL)
|
|
348
|
+
break;
|
|
345
349
|
}
|
|
346
350
|
return false;
|
|
347
351
|
}
|
package/vendor/re2/compile.cc
CHANGED
package/vendor/re2/dfa.cc
CHANGED
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
#include "util/logging.h"
|
|
40
40
|
#include "util/mix.h"
|
|
41
41
|
#include "util/mutex.h"
|
|
42
|
-
#include "util/pod_array.h"
|
|
43
|
-
#include "util/sparse_set.h"
|
|
44
42
|
#include "util/strutil.h"
|
|
43
|
+
#include "re2/pod_array.h"
|
|
45
44
|
#include "re2/prog.h"
|
|
45
|
+
#include "re2/sparse_set.h"
|
|
46
46
|
#include "re2/stringpiece.h"
|
|
47
47
|
|
|
48
48
|
// Silence "zero-sized array in struct/union" warning for DFA::State::next_.
|
|
@@ -442,7 +442,7 @@ DFA::DFA(Prog* prog, Prog::MatchKind kind, int64_t max_mem)
|
|
|
442
442
|
q1_(NULL),
|
|
443
443
|
mem_budget_(max_mem) {
|
|
444
444
|
if (ExtraDebug)
|
|
445
|
-
fprintf(stderr, "\nkind %d\n%s\n",
|
|
445
|
+
fprintf(stderr, "\nkind %d\n%s\n", kind_, prog_->DumpUnanchored().c_str());
|
|
446
446
|
int nmark = 0;
|
|
447
447
|
if (kind_ == Prog::kLongestMatch)
|
|
448
448
|
nmark = prog_->size();
|
|
@@ -989,8 +989,8 @@ void DFA::RunWorkqOnByte(Workq* oldq, Workq* newq,
|
|
|
989
989
|
}
|
|
990
990
|
|
|
991
991
|
if (ExtraDebug)
|
|
992
|
-
fprintf(stderr, "%s on %d[%#x] -> %s [%d]\n",
|
|
993
|
-
c, flag, DumpWorkq(newq).c_str(), *ismatch);
|
|
992
|
+
fprintf(stderr, "%s on %d[%#x] -> %s [%d]\n",
|
|
993
|
+
DumpWorkq(oldq).c_str(), c, flag, DumpWorkq(newq).c_str(), *ismatch);
|
|
994
994
|
}
|
|
995
995
|
|
|
996
996
|
// Processes input byte c in state, returning new state.
|
|
@@ -1367,8 +1367,7 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params,
|
|
|
1367
1367
|
|
|
1368
1368
|
while (p != ep) {
|
|
1369
1369
|
if (ExtraDebug)
|
|
1370
|
-
fprintf(stderr, "@%td: %s\n",
|
|
1371
|
-
p - bp, DumpState(s).c_str());
|
|
1370
|
+
fprintf(stderr, "@%td: %s\n", p - bp, DumpState(s).c_str());
|
|
1372
1371
|
|
|
1373
1372
|
if (have_first_byte && s == start) {
|
|
1374
1373
|
// In start state, only way out is to find first_byte,
|
|
@@ -1476,8 +1475,7 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params,
|
|
|
1476
1475
|
else
|
|
1477
1476
|
lastmatch = p + 1;
|
|
1478
1477
|
if (ExtraDebug)
|
|
1479
|
-
fprintf(stderr, "match @%td! [%s]\n",
|
|
1480
|
-
lastmatch - bp, DumpState(s).c_str());
|
|
1478
|
+
fprintf(stderr, "match @%td! [%s]\n", lastmatch - bp, DumpState(s).c_str());
|
|
1481
1479
|
if (params->matches != NULL && kind_ == Prog::kManyMatch) {
|
|
1482
1480
|
for (int i = s->ninst_ - 1; i >= 0; i--) {
|
|
1483
1481
|
int id = s->inst_[i];
|
|
@@ -1780,8 +1778,7 @@ bool DFA::Search(const StringPiece& text,
|
|
|
1780
1778
|
if (ExtraDebug) {
|
|
1781
1779
|
fprintf(stderr, "\nprogram:\n%s\n", prog_->DumpUnanchored().c_str());
|
|
1782
1780
|
fprintf(stderr, "text %s anchored=%d earliest=%d fwd=%d kind %d\n",
|
|
1783
|
-
std::string(text).c_str(), anchored, want_earliest_match,
|
|
1784
|
-
run_forward, kind_);
|
|
1781
|
+
std::string(text).c_str(), anchored, want_earliest_match, run_forward, kind_);
|
|
1785
1782
|
}
|
|
1786
1783
|
|
|
1787
1784
|
RWLocker l(&cache_mutex_);
|
package/vendor/re2/nfa.cc
CHANGED
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
#include <utility>
|
|
32
32
|
#include <vector>
|
|
33
33
|
|
|
34
|
-
#include "re2/prog.h"
|
|
35
|
-
#include "re2/regexp.h"
|
|
36
34
|
#include "util/logging.h"
|
|
37
|
-
#include "util/pod_array.h"
|
|
38
|
-
#include "util/sparse_array.h"
|
|
39
|
-
#include "util/sparse_set.h"
|
|
40
35
|
#include "util/strutil.h"
|
|
36
|
+
#include "re2/pod_array.h"
|
|
37
|
+
#include "re2/prog.h"
|
|
38
|
+
#include "re2/regexp.h"
|
|
39
|
+
#include "re2/sparse_array.h"
|
|
40
|
+
#include "re2/sparse_set.h"
|
|
41
41
|
|
|
42
42
|
namespace re2 {
|
|
43
43
|
|
|
@@ -382,10 +382,15 @@ int NFA::Step(Threadq* runq, Threadq* nextq, int c, const StringPiece& context,
|
|
|
382
382
|
break;
|
|
383
383
|
|
|
384
384
|
case kInstMatch: {
|
|
385
|
-
// Avoid invoking undefined behavior
|
|
386
|
-
//
|
|
387
|
-
|
|
385
|
+
// Avoid invoking undefined behavior (arithmetic on a null pointer)
|
|
386
|
+
// by storing p instead of p-1. (What would the latter even mean?!)
|
|
387
|
+
// This complements the special case in NFA::Search().
|
|
388
|
+
if (p == NULL) {
|
|
389
|
+
CopyCapture(match_, t->capture);
|
|
390
|
+
match_[1] = p;
|
|
391
|
+
matched_ = true;
|
|
388
392
|
break;
|
|
393
|
+
}
|
|
389
394
|
|
|
390
395
|
if (endmatch_ && p-1 != etext_)
|
|
391
396
|
break;
|
|
@@ -431,12 +436,12 @@ std::string NFA::FormatCapture(const char** capture) {
|
|
|
431
436
|
if (capture[i] == NULL)
|
|
432
437
|
s += "(?,?)";
|
|
433
438
|
else if (capture[i+1] == NULL)
|
|
434
|
-
s += StringPrintf("(%
|
|
435
|
-
|
|
439
|
+
s += StringPrintf("(%td,?)",
|
|
440
|
+
capture[i] - btext_);
|
|
436
441
|
else
|
|
437
|
-
s += StringPrintf("(%
|
|
438
|
-
|
|
439
|
-
|
|
442
|
+
s += StringPrintf("(%td,%td)",
|
|
443
|
+
capture[i] - btext_,
|
|
444
|
+
capture[i+1] - btext_);
|
|
440
445
|
}
|
|
441
446
|
return s;
|
|
442
447
|
}
|
|
@@ -493,8 +498,7 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,
|
|
|
493
498
|
|
|
494
499
|
if (ExtraDebug)
|
|
495
500
|
fprintf(stderr, "NFA::Search %s (context: %s) anchored=%d longest=%d\n",
|
|
496
|
-
std::string(text).c_str(), std::string(context).c_str(), anchored,
|
|
497
|
-
longest);
|
|
501
|
+
std::string(text).c_str(), std::string(context).c_str(), anchored, longest);
|
|
498
502
|
|
|
499
503
|
// Set up search.
|
|
500
504
|
Threadq* runq = &q0_;
|
|
@@ -594,6 +598,18 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,
|
|
|
594
598
|
fprintf(stderr, "dead\n");
|
|
595
599
|
break;
|
|
596
600
|
}
|
|
601
|
+
|
|
602
|
+
// Avoid invoking undefined behavior (arithmetic on a null pointer)
|
|
603
|
+
// by simply not continuing the loop.
|
|
604
|
+
// This complements the special case in NFA::Step().
|
|
605
|
+
if (p == NULL) {
|
|
606
|
+
(void)Step(runq, nextq, p < etext_ ? p[0] & 0xFF : -1, context, p);
|
|
607
|
+
DCHECK_EQ(runq->size(), 0);
|
|
608
|
+
using std::swap;
|
|
609
|
+
swap(nextq, runq);
|
|
610
|
+
nextq->clear();
|
|
611
|
+
break;
|
|
612
|
+
}
|
|
597
613
|
}
|
|
598
614
|
|
|
599
615
|
for (Threadq::iterator i = runq->begin(); i != runq->end(); ++i)
|
|
@@ -606,7 +622,8 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,
|
|
|
606
622
|
static_cast<size_t>(match_[2 * i + 1] - match_[2 * i]));
|
|
607
623
|
if (ExtraDebug)
|
|
608
624
|
fprintf(stderr, "match (%td,%td)\n",
|
|
609
|
-
match_[0] - btext_,
|
|
625
|
+
match_[0] - btext_,
|
|
626
|
+
match_[1] - btext_);
|
|
610
627
|
return true;
|
|
611
628
|
}
|
|
612
629
|
return false;
|
package/vendor/re2/onepass.cc
CHANGED
|
@@ -59,11 +59,11 @@
|
|
|
59
59
|
|
|
60
60
|
#include "util/util.h"
|
|
61
61
|
#include "util/logging.h"
|
|
62
|
-
#include "util/pod_array.h"
|
|
63
|
-
#include "util/sparse_set.h"
|
|
64
62
|
#include "util/strutil.h"
|
|
65
63
|
#include "util/utf.h"
|
|
64
|
+
#include "re2/pod_array.h"
|
|
66
65
|
#include "re2/prog.h"
|
|
66
|
+
#include "re2/sparse_set.h"
|
|
67
67
|
#include "re2/stringpiece.h"
|
|
68
68
|
|
|
69
69
|
// Silence "zero-sized array in struct/union" warning for OneState::action.
|
|
@@ -550,7 +550,7 @@ bool Prog::IsOnePass() {
|
|
|
550
550
|
if (!AddQ(&workq, ip->out())) {
|
|
551
551
|
if (ExtraDebug)
|
|
552
552
|
LOG(ERROR) << StringPrintf(
|
|
553
|
-
"Not OnePass: multiple paths %d -> %d
|
|
553
|
+
"Not OnePass: multiple paths %d -> %d", *it, ip->out());
|
|
554
554
|
goto fail;
|
|
555
555
|
}
|
|
556
556
|
id = ip->out();
|
|
@@ -561,7 +561,7 @@ bool Prog::IsOnePass() {
|
|
|
561
561
|
// (3) is violated
|
|
562
562
|
if (ExtraDebug)
|
|
563
563
|
LOG(ERROR) << StringPrintf(
|
|
564
|
-
"Not OnePass: multiple matches from %d
|
|
564
|
+
"Not OnePass: multiple matches from %d", *it);
|
|
565
565
|
goto fail;
|
|
566
566
|
}
|
|
567
567
|
matched = true;
|
package/vendor/re2/parse.cc
CHANGED
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
|
|
28
28
|
#include "util/util.h"
|
|
29
29
|
#include "util/logging.h"
|
|
30
|
-
#include "util/pod_array.h"
|
|
31
30
|
#include "util/strutil.h"
|
|
32
31
|
#include "util/utf.h"
|
|
32
|
+
#include "re2/pod_array.h"
|
|
33
33
|
#include "re2/regexp.h"
|
|
34
34
|
#include "re2/stringpiece.h"
|
|
35
35
|
#include "re2/unicode_casefold.h"
|
|
@@ -1323,14 +1323,14 @@ bool Regexp::ParseState::MaybeConcatString(int r, ParseFlags flags) {
|
|
|
1323
1323
|
// Parses a decimal integer, storing it in *np.
|
|
1324
1324
|
// Sets *s to span the remainder of the string.
|
|
1325
1325
|
static bool ParseInteger(StringPiece* s, int* np) {
|
|
1326
|
-
if (s->
|
|
1326
|
+
if (s->empty() || !isdigit((*s)[0] & 0xFF))
|
|
1327
1327
|
return false;
|
|
1328
1328
|
// Disallow leading zeros.
|
|
1329
1329
|
if (s->size() >= 2 && (*s)[0] == '0' && isdigit((*s)[1] & 0xFF))
|
|
1330
1330
|
return false;
|
|
1331
1331
|
int n = 0;
|
|
1332
1332
|
int c;
|
|
1333
|
-
while (s->
|
|
1333
|
+
while (!s->empty() && isdigit(c = (*s)[0] & 0xFF)) {
|
|
1334
1334
|
// Avoid overflow.
|
|
1335
1335
|
if (n >= 100000000)
|
|
1336
1336
|
return false;
|
|
@@ -1352,16 +1352,16 @@ static bool ParseInteger(StringPiece* s, int* np) {
|
|
|
1352
1352
|
// s must NOT be edited unless MaybeParseRepetition returns true.
|
|
1353
1353
|
static bool MaybeParseRepetition(StringPiece* sp, int* lo, int* hi) {
|
|
1354
1354
|
StringPiece s = *sp;
|
|
1355
|
-
if (s.
|
|
1355
|
+
if (s.empty() || s[0] != '{')
|
|
1356
1356
|
return false;
|
|
1357
1357
|
s.remove_prefix(1); // '{'
|
|
1358
1358
|
if (!ParseInteger(&s, lo))
|
|
1359
1359
|
return false;
|
|
1360
|
-
if (s.
|
|
1360
|
+
if (s.empty())
|
|
1361
1361
|
return false;
|
|
1362
1362
|
if (s[0] == ',') {
|
|
1363
1363
|
s.remove_prefix(1); // ','
|
|
1364
|
-
if (s.
|
|
1364
|
+
if (s.empty())
|
|
1365
1365
|
return false;
|
|
1366
1366
|
if (s[0] == '}') {
|
|
1367
1367
|
// {2,} means at least 2
|
|
@@ -1375,7 +1375,7 @@ static bool MaybeParseRepetition(StringPiece* sp, int* lo, int* hi) {
|
|
|
1375
1375
|
// {2} means exactly two
|
|
1376
1376
|
*hi = *lo;
|
|
1377
1377
|
}
|
|
1378
|
-
if (s.
|
|
1378
|
+
if (s.empty() || s[0] != '}')
|
|
1379
1379
|
return false;
|
|
1380
1380
|
s.remove_prefix(1); // '}'
|
|
1381
1381
|
*sp = s;
|
|
@@ -1416,7 +1416,7 @@ static int StringPieceToRune(Rune *r, StringPiece *sp, RegexpStatus* status) {
|
|
|
1416
1416
|
static bool IsValidUTF8(const StringPiece& s, RegexpStatus* status) {
|
|
1417
1417
|
StringPiece t = s;
|
|
1418
1418
|
Rune r;
|
|
1419
|
-
while (t.
|
|
1419
|
+
while (!t.empty()) {
|
|
1420
1420
|
if (StringPieceToRune(&r, &t, status) < 0)
|
|
1421
1421
|
return false;
|
|
1422
1422
|
}
|
|
@@ -1448,13 +1448,13 @@ static int UnHex(int c) {
|
|
|
1448
1448
|
static bool ParseEscape(StringPiece* s, Rune* rp,
|
|
1449
1449
|
RegexpStatus* status, int rune_max) {
|
|
1450
1450
|
const char* begin = s->data();
|
|
1451
|
-
if (s->
|
|
1451
|
+
if (s->empty() || (*s)[0] != '\\') {
|
|
1452
1452
|
// Should not happen - caller always checks.
|
|
1453
1453
|
status->set_code(kRegexpInternalError);
|
|
1454
1454
|
status->set_error_arg(StringPiece());
|
|
1455
1455
|
return false;
|
|
1456
1456
|
}
|
|
1457
|
-
if (s->size()
|
|
1457
|
+
if (s->size() == 1) {
|
|
1458
1458
|
status->set_code(kRegexpTrailingBackslash);
|
|
1459
1459
|
status->set_error_arg(StringPiece());
|
|
1460
1460
|
return false;
|
|
@@ -1485,16 +1485,16 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
|
|
|
1485
1485
|
case '6':
|
|
1486
1486
|
case '7':
|
|
1487
1487
|
// Single non-zero octal digit is a backreference; not supported.
|
|
1488
|
-
if (s->
|
|
1488
|
+
if (s->empty() || (*s)[0] < '0' || (*s)[0] > '7')
|
|
1489
1489
|
goto BadEscape;
|
|
1490
1490
|
FALLTHROUGH_INTENDED;
|
|
1491
1491
|
case '0':
|
|
1492
1492
|
// consume up to three octal digits; already have one.
|
|
1493
1493
|
code = c - '0';
|
|
1494
|
-
if (s->
|
|
1494
|
+
if (!s->empty() && '0' <= (c = (*s)[0]) && c <= '7') {
|
|
1495
1495
|
code = code * 8 + c - '0';
|
|
1496
1496
|
s->remove_prefix(1); // digit
|
|
1497
|
-
if (s->
|
|
1497
|
+
if (!s->empty()) {
|
|
1498
1498
|
c = (*s)[0];
|
|
1499
1499
|
if ('0' <= c && c <= '7') {
|
|
1500
1500
|
code = code * 8 + c - '0';
|
|
@@ -1509,7 +1509,7 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
|
|
|
1509
1509
|
|
|
1510
1510
|
// Hexadecimal escapes
|
|
1511
1511
|
case 'x':
|
|
1512
|
-
if (s->
|
|
1512
|
+
if (s->empty())
|
|
1513
1513
|
goto BadEscape;
|
|
1514
1514
|
if (StringPieceToRune(&c, s, status) < 0)
|
|
1515
1515
|
return false;
|
|
@@ -1529,7 +1529,7 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
|
|
|
1529
1529
|
code = code * 16 + UnHex(c);
|
|
1530
1530
|
if (code > rune_max)
|
|
1531
1531
|
goto BadEscape;
|
|
1532
|
-
if (s->
|
|
1532
|
+
if (s->empty())
|
|
1533
1533
|
goto BadEscape;
|
|
1534
1534
|
if (StringPieceToRune(&c, s, status) < 0)
|
|
1535
1535
|
return false;
|
|
@@ -1540,7 +1540,7 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
|
|
|
1540
1540
|
return true;
|
|
1541
1541
|
}
|
|
1542
1542
|
// Easy case: two hex digits.
|
|
1543
|
-
if (s->
|
|
1543
|
+
if (s->empty())
|
|
1544
1544
|
goto BadEscape;
|
|
1545
1545
|
if (StringPieceToRune(&c1, s, status) < 0)
|
|
1546
1546
|
return false;
|
|
@@ -1771,7 +1771,7 @@ ParseStatus ParseUnicodeGroup(StringPiece* s, Regexp::ParseFlags parse_flags,
|
|
|
1771
1771
|
// Chop seq where s now begins.
|
|
1772
1772
|
seq = StringPiece(seq.data(), static_cast<size_t>(s->data() - seq.data()));
|
|
1773
1773
|
|
|
1774
|
-
if (name.
|
|
1774
|
+
if (!name.empty() && name[0] == '^') {
|
|
1775
1775
|
sign = -sign;
|
|
1776
1776
|
name.remove_prefix(1); // '^'
|
|
1777
1777
|
}
|
|
@@ -1858,7 +1858,7 @@ static ParseStatus ParseCCName(StringPiece* s, Regexp::ParseFlags parse_flags,
|
|
|
1858
1858
|
bool Regexp::ParseState::ParseCCCharacter(StringPiece* s, Rune *rp,
|
|
1859
1859
|
const StringPiece& whole_class,
|
|
1860
1860
|
RegexpStatus* status) {
|
|
1861
|
-
if (s->
|
|
1861
|
+
if (s->empty()) {
|
|
1862
1862
|
status->set_code(kRegexpMissingBracket);
|
|
1863
1863
|
status->set_error_arg(whole_class);
|
|
1864
1864
|
return false;
|
|
@@ -1866,7 +1866,7 @@ bool Regexp::ParseState::ParseCCCharacter(StringPiece* s, Rune *rp,
|
|
|
1866
1866
|
|
|
1867
1867
|
// Allow regular escape sequences even though
|
|
1868
1868
|
// many need not be escaped in this context.
|
|
1869
|
-
if (
|
|
1869
|
+
if ((*s)[0] == '\\')
|
|
1870
1870
|
return ParseEscape(s, rp, status, rune_max_);
|
|
1871
1871
|
|
|
1872
1872
|
// Otherwise take the next rune.
|
|
@@ -1908,7 +1908,7 @@ bool Regexp::ParseState::ParseCharClass(StringPiece* s,
|
|
|
1908
1908
|
Regexp** out_re,
|
|
1909
1909
|
RegexpStatus* status) {
|
|
1910
1910
|
StringPiece whole_class = *s;
|
|
1911
|
-
if (s->
|
|
1911
|
+
if (s->empty() || (*s)[0] != '[') {
|
|
1912
1912
|
// Caller checked this.
|
|
1913
1913
|
status->set_code(kRegexpInternalError);
|
|
1914
1914
|
status->set_error_arg(StringPiece());
|
|
@@ -1918,7 +1918,7 @@ bool Regexp::ParseState::ParseCharClass(StringPiece* s,
|
|
|
1918
1918
|
Regexp* re = new Regexp(kRegexpCharClass, flags_ & ~FoldCase);
|
|
1919
1919
|
re->ccb_ = new CharClassBuilder;
|
|
1920
1920
|
s->remove_prefix(1); // '['
|
|
1921
|
-
if (s->
|
|
1921
|
+
if (!s->empty() && (*s)[0] == '^') {
|
|
1922
1922
|
s->remove_prefix(1); // '^'
|
|
1923
1923
|
negated = true;
|
|
1924
1924
|
if (!(flags_ & ClassNL) || (flags_ & NeverNL)) {
|
|
@@ -1928,7 +1928,7 @@ bool Regexp::ParseState::ParseCharClass(StringPiece* s,
|
|
|
1928
1928
|
}
|
|
1929
1929
|
}
|
|
1930
1930
|
bool first = true; // ] is okay as first char in class
|
|
1931
|
-
while (s->
|
|
1931
|
+
while (!s->empty() && ((*s)[0] != ']' || first)) {
|
|
1932
1932
|
// - is only okay unescaped as first or last in class.
|
|
1933
1933
|
// Except that Perl allows - anywhere.
|
|
1934
1934
|
if ((*s)[0] == '-' && !first && !(flags_&PerlX) &&
|
|
@@ -1996,7 +1996,7 @@ bool Regexp::ParseState::ParseCharClass(StringPiece* s,
|
|
|
1996
1996
|
// in the flags.
|
|
1997
1997
|
re->ccb_->AddRangeFlags(rr.lo, rr.hi, flags_ | Regexp::ClassNL);
|
|
1998
1998
|
}
|
|
1999
|
-
if (s->
|
|
1999
|
+
if (s->empty()) {
|
|
2000
2000
|
status->set_code(kRegexpMissingBracket);
|
|
2001
2001
|
status->set_error_arg(whole_class);
|
|
2002
2002
|
re->Decref();
|
|
@@ -2016,7 +2016,7 @@ bool Regexp::ParseState::ParseCharClass(StringPiece* s,
|
|
|
2016
2016
|
// Python rejects names starting with digits.
|
|
2017
2017
|
// We don't enforce either of those.
|
|
2018
2018
|
static bool IsValidCaptureName(const StringPiece& name) {
|
|
2019
|
-
if (name.
|
|
2019
|
+
if (name.empty())
|
|
2020
2020
|
return false;
|
|
2021
2021
|
for (size_t i = 0; i < name.size(); i++) {
|
|
2022
2022
|
int c = name[i];
|
|
@@ -2099,7 +2099,7 @@ bool Regexp::ParseState::ParsePerlFlags(StringPiece* s) {
|
|
|
2099
2099
|
int nflags = flags_;
|
|
2100
2100
|
Rune c;
|
|
2101
2101
|
for (bool done = false; !done; ) {
|
|
2102
|
-
if (t.
|
|
2102
|
+
if (t.empty())
|
|
2103
2103
|
goto BadPerlOp;
|
|
2104
2104
|
if (StringPieceToRune(&c, &t, status_) < 0)
|
|
2105
2105
|
return false;
|
|
@@ -2217,7 +2217,7 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
|
|
|
2217
2217
|
|
|
2218
2218
|
if (global_flags & Literal) {
|
|
2219
2219
|
// Special parse loop for literal string.
|
|
2220
|
-
while (t.
|
|
2220
|
+
while (!t.empty()) {
|
|
2221
2221
|
Rune r;
|
|
2222
2222
|
if (StringPieceToRune(&r, &t, status) < 0)
|
|
2223
2223
|
return NULL;
|
|
@@ -2228,7 +2228,7 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
|
|
|
2228
2228
|
}
|
|
2229
2229
|
|
|
2230
2230
|
StringPiece lastunary = StringPiece();
|
|
2231
|
-
while (t.
|
|
2231
|
+
while (!t.empty()) {
|
|
2232
2232
|
StringPiece isunary = StringPiece();
|
|
2233
2233
|
switch (t[0]) {
|
|
2234
2234
|
default: {
|
|
@@ -2312,11 +2312,11 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
|
|
|
2312
2312
|
bool nongreedy = false;
|
|
2313
2313
|
t.remove_prefix(1); // '*' or '+' or '?'
|
|
2314
2314
|
if (ps.flags() & PerlX) {
|
|
2315
|
-
if (t.
|
|
2315
|
+
if (!t.empty() && t[0] == '?') {
|
|
2316
2316
|
nongreedy = true;
|
|
2317
2317
|
t.remove_prefix(1); // '?'
|
|
2318
2318
|
}
|
|
2319
|
-
if (lastunary.
|
|
2319
|
+
if (!lastunary.empty()) {
|
|
2320
2320
|
// In Perl it is not allowed to stack repetition operators:
|
|
2321
2321
|
// a** is a syntax error, not a double-star.
|
|
2322
2322
|
// (and a++ means something else entirely, which we don't support!)
|
|
@@ -2347,11 +2347,11 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
|
|
|
2347
2347
|
}
|
|
2348
2348
|
bool nongreedy = false;
|
|
2349
2349
|
if (ps.flags() & PerlX) {
|
|
2350
|
-
if (t.
|
|
2350
|
+
if (!t.empty() && t[0] == '?') {
|
|
2351
2351
|
nongreedy = true;
|
|
2352
2352
|
t.remove_prefix(1); // '?'
|
|
2353
2353
|
}
|
|
2354
|
-
if (lastunary.
|
|
2354
|
+
if (!lastunary.empty()) {
|
|
2355
2355
|
// Not allowed to stack repetition operators.
|
|
2356
2356
|
status->set_code(kRegexpRepeatOp);
|
|
2357
2357
|
status->set_error_arg(StringPiece(
|
|
@@ -2405,7 +2405,7 @@ Regexp* Regexp::Parse(const StringPiece& s, ParseFlags global_flags,
|
|
|
2405
2405
|
|
|
2406
2406
|
if (t[1] == 'Q') { // \Q ... \E: the ... is always literals
|
|
2407
2407
|
t.remove_prefix(2); // '\\', 'Q'
|
|
2408
|
-
while (t.
|
|
2408
|
+
while (!t.empty()) {
|
|
2409
2409
|
if (t.size() >= 2 && t[0] == '\\' && t[1] == 'E') {
|
|
2410
2410
|
t.remove_prefix(2); // '\\', 'E'
|
|
2411
2411
|
break;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Use of this source code is governed by a BSD-style
|
|
3
3
|
// license that can be found in the LICENSE file.
|
|
4
4
|
|
|
5
|
-
#ifndef
|
|
6
|
-
#define
|
|
5
|
+
#ifndef RE2_POD_ARRAY_H_
|
|
6
|
+
#define RE2_POD_ARRAY_H_
|
|
7
7
|
|
|
8
8
|
#include <memory>
|
|
9
9
|
#include <type_traits>
|
|
@@ -52,4 +52,4 @@ class PODArray {
|
|
|
52
52
|
|
|
53
53
|
} // namespace re2
|
|
54
54
|
|
|
55
|
-
#endif //
|
|
55
|
+
#endif // RE2_POD_ARRAY_H_
|
package/vendor/re2/prog.h
CHANGED
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
|
|
19
19
|
#include "util/util.h"
|
|
20
20
|
#include "util/logging.h"
|
|
21
|
-
#include "
|
|
22
|
-
#include "util/sparse_array.h"
|
|
23
|
-
#include "util/sparse_set.h"
|
|
21
|
+
#include "re2/pod_array.h"
|
|
24
22
|
#include "re2/re2.h"
|
|
23
|
+
#include "re2/sparse_array.h"
|
|
24
|
+
#include "re2/sparse_set.h"
|
|
25
25
|
|
|
26
26
|
namespace re2 {
|
|
27
27
|
|
package/vendor/re2/re2.cc
CHANGED
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
|
|
25
25
|
#include "util/util.h"
|
|
26
26
|
#include "util/logging.h"
|
|
27
|
-
#include "util/sparse_array.h"
|
|
28
27
|
#include "util/strutil.h"
|
|
29
28
|
#include "util/utf.h"
|
|
30
29
|
#include "re2/prog.h"
|
|
31
30
|
#include "re2/regexp.h"
|
|
31
|
+
#include "re2/sparse_array.h"
|
|
32
32
|
|
|
33
33
|
namespace re2 {
|
|
34
34
|
|
|
@@ -408,7 +408,7 @@ int RE2::GlobalReplace(std::string* str,
|
|
|
408
408
|
break;
|
|
409
409
|
if (p < vec[0].data())
|
|
410
410
|
out.append(p, vec[0].data() - p);
|
|
411
|
-
if (vec[0].data() == lastend && vec[0].
|
|
411
|
+
if (vec[0].data() == lastend && vec[0].empty()) {
|
|
412
412
|
// Disallow empty match at end of last match: skip ahead.
|
|
413
413
|
//
|
|
414
414
|
// fullrune() takes int, not ptrdiff_t. However, it just looks
|
|
@@ -934,7 +934,7 @@ bool RE2::Rewrite(std::string* out,
|
|
|
934
934
|
return false;
|
|
935
935
|
}
|
|
936
936
|
StringPiece snip = vec[n];
|
|
937
|
-
if (snip.
|
|
937
|
+
if (!snip.empty())
|
|
938
938
|
out->append(snip.data(), snip.size());
|
|
939
939
|
} else if (c == '\\') {
|
|
940
940
|
out->push_back('\\');
|
package/vendor/re2/set.cc
CHANGED
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
|
|
11
11
|
#include "util/util.h"
|
|
12
12
|
#include "util/logging.h"
|
|
13
|
-
#include "
|
|
14
|
-
#include "re2/stringpiece.h"
|
|
13
|
+
#include "re2/pod_array.h"
|
|
15
14
|
#include "re2/prog.h"
|
|
16
15
|
#include "re2/re2.h"
|
|
17
16
|
#include "re2/regexp.h"
|
|
17
|
+
#include "re2/stringpiece.h"
|
|
18
18
|
|
|
19
19
|
namespace re2 {
|
|
20
20
|
|