re2 1.17.1 → 1.17.4
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/README.md +7 -0
- package/lib/replace.cc +44 -41
- package/package.json +4 -4
- package/tests/test_replace.js +278 -227
- package/vendor/re2/fuzzing/compiler-rt/include/fuzzer/FuzzedDataProvider.h +328 -236
- package/vendor/re2/make_unicode_casefold.py +1 -1
- package/vendor/re2/make_unicode_groups.py +1 -1
- package/vendor/re2/prog.cc +5 -2
- package/vendor/re2/re2.h +1 -1
- package/vendor/re2/regexp.cc +1 -2
package/README.md
CHANGED
|
@@ -13,6 +13,10 @@ at his [Implementing Regular Expressions](http://swtch.com/~rsc/regexp/) page.
|
|
|
13
13
|
(see [Syntax](https://github.com/google/re2/wiki/Syntax)),
|
|
14
14
|
but it lacks two features: backreferences and lookahead assertions. See below for more details.
|
|
15
15
|
|
|
16
|
+
`RE2` always works in the [Unicode mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode), which means that all matches that use character codes are interpret as Unicode code points, not as binary values of UTF-16.
|
|
17
|
+
See `RE2.unicodeWarningLevel` below for more details.
|
|
18
|
+
|
|
19
|
+
|
|
16
20
|
`RE2` object emulates standard `RegExp` making it a practical drop-in replacement in most cases.
|
|
17
21
|
`RE2` is extended to provide `String`-based regular expression methods as well. To help to convert
|
|
18
22
|
`RegExp` objects to `RE2` its constructor can take `RegExp` directly honoring all properties.
|
|
@@ -343,6 +347,9 @@ console.log('re2_res : ' + re2_res); // prints: re2_res : abc,a,b,c
|
|
|
343
347
|
|
|
344
348
|
## Release history
|
|
345
349
|
|
|
350
|
+
- 1.17.4 *Updated deps.*
|
|
351
|
+
- 1.17.3 *Fixed bug with zero-length replacements.*
|
|
352
|
+
- 1.17.2 *Added support for the enhanced local mirroring by updating [install-artifact-from-github](https://github.com/uhop/install-artifact-from-github).*
|
|
346
353
|
- 1.17.1 *Fix for `lastIndex` for U+10000 - U+10FFFF UTF characters. Thx, [omg](https://github.com/omg).*
|
|
347
354
|
- 1.17.0 *Updated GYP, added support for Node 17, updated deps.*
|
|
348
355
|
- 1.16.0 *Updated the compiler (thx, [Sergei Dyshel](https://github.com/sergei-dyshel)), updated GYP, removed support for Node 10, added support for Node 16, updated TS bindings (thx, [BannerBomb](https://github.com/BannerBomb)).*
|
package/lib/replace.cc
CHANGED
|
@@ -228,7 +228,9 @@ static Nan::Maybe<std::string> replace(WrappedRE2 *re2, const StrVal &replacee,
|
|
|
228
228
|
{
|
|
229
229
|
size_t s = getUtf8CharSize(data[lastIndex]);
|
|
230
230
|
lastIndex += s;
|
|
231
|
-
if (s == 4 && n >= 2)
|
|
231
|
+
if (s == 4 && n >= 2) {
|
|
232
|
+
--n; // this utf8 character will take two utf16 characters
|
|
233
|
+
}
|
|
232
234
|
// the decrement above is protected to avoid an overflow of an unsigned integer
|
|
233
235
|
}
|
|
234
236
|
}
|
|
@@ -245,28 +247,30 @@ static Nan::Maybe<std::string> replace(WrappedRE2 *re2, const StrVal &replacee,
|
|
|
245
247
|
while (lastIndex <= size && re2->regexp.Match(str, lastIndex, size, anchor, &groups[0], groups.size()))
|
|
246
248
|
{
|
|
247
249
|
noMatch = false;
|
|
250
|
+
auto offset = match.data() - data;
|
|
248
251
|
if (!re2->global && re2->sticky)
|
|
249
252
|
{
|
|
250
|
-
re2->lastIndex += replacee.isBuffer ?
|
|
253
|
+
re2->lastIndex += replacee.isBuffer ? offset + match.size() - lastIndex : getUtf16Length(data + lastIndex, match.data() + match.size());
|
|
254
|
+
}
|
|
255
|
+
if (match.data() == data || offset > static_cast<long>(lastIndex))
|
|
256
|
+
{
|
|
257
|
+
result += std::string(data + lastIndex, offset - lastIndex);
|
|
251
258
|
}
|
|
259
|
+
result += replace(replacer, replacer_size, groups, str, namedGroups);
|
|
252
260
|
if (match.size())
|
|
253
261
|
{
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
262
|
+
lastIndex = offset + match.size();
|
|
263
|
+
}
|
|
264
|
+
else if (offset < size)
|
|
265
|
+
{
|
|
266
|
+
auto sym_size = getUtf8CharSize(data[offset]);
|
|
267
|
+
result.append(data + offset, sym_size);
|
|
268
|
+
lastIndex = offset + sym_size;
|
|
260
269
|
}
|
|
261
270
|
else
|
|
262
271
|
{
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (lastIndex < size)
|
|
266
|
-
{
|
|
267
|
-
result.append(data + lastIndex, sym_size);
|
|
268
|
-
}
|
|
269
|
-
lastIndex += sym_size;
|
|
272
|
+
lastIndex = size;
|
|
273
|
+
break;
|
|
270
274
|
}
|
|
271
275
|
if (!re2->global)
|
|
272
276
|
{
|
|
@@ -295,7 +299,7 @@ static Nan::Maybe<std::string> replace(WrappedRE2 *re2, const StrVal &replacee,
|
|
|
295
299
|
|
|
296
300
|
inline Nan::Maybe<std::string> replace(const Nan::Callback *replacer, const std::vector<re2::StringPiece> &groups, const re2::StringPiece &str, const v8::Local<v8::Value> &input, bool useBuffers, const std::map<std::string, int> &namedGroups)
|
|
297
301
|
{
|
|
298
|
-
std::vector<v8::Local<v8::Value
|
|
302
|
+
std::vector<v8::Local<v8::Value> > argv;
|
|
299
303
|
|
|
300
304
|
auto context = Nan::GetCurrentContext();
|
|
301
305
|
|
|
@@ -377,7 +381,9 @@ static Nan::Maybe<std::string> replace(WrappedRE2 *re2, const StrVal &replacee,
|
|
|
377
381
|
{
|
|
378
382
|
size_t s = getUtf8CharSize(data[lastIndex]);
|
|
379
383
|
lastIndex += s;
|
|
380
|
-
if (s == 4 && n >= 2)
|
|
384
|
+
if (s == 4 && n >= 2) {
|
|
385
|
+
--n; // this utf8 character will take two utf16 characters
|
|
386
|
+
}
|
|
381
387
|
// the decrement above is protected to avoid an overflow of an unsigned integer
|
|
382
388
|
}
|
|
383
389
|
}
|
|
@@ -396,38 +402,35 @@ static Nan::Maybe<std::string> replace(WrappedRE2 *re2, const StrVal &replacee,
|
|
|
396
402
|
while (lastIndex <= size && re2->regexp.Match(str, lastIndex, size, anchor, &groups[0], groups.size()))
|
|
397
403
|
{
|
|
398
404
|
noMatch = false;
|
|
405
|
+
auto offset = match.data() - data;
|
|
399
406
|
if (!re2->global && re2->sticky)
|
|
400
407
|
{
|
|
401
|
-
re2->lastIndex += replacee.isBuffer ?
|
|
408
|
+
re2->lastIndex += replacee.isBuffer ? offset + match.size() - lastIndex : getUtf16Length(data + lastIndex, match.data() + match.size());
|
|
409
|
+
}
|
|
410
|
+
if (match.data() == data || offset > static_cast<long>(lastIndex))
|
|
411
|
+
{
|
|
412
|
+
result += std::string(data + lastIndex, offset - lastIndex);
|
|
402
413
|
}
|
|
414
|
+
const auto part = replace(replacer, groups, str, input, useBuffers, namedGroups);
|
|
415
|
+
if (part.IsNothing())
|
|
416
|
+
{
|
|
417
|
+
return part;
|
|
418
|
+
}
|
|
419
|
+
result += part.FromJust();
|
|
403
420
|
if (match.size())
|
|
404
421
|
{
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
return part;
|
|
413
|
-
}
|
|
414
|
-
result += part.FromJust();
|
|
415
|
-
lastIndex = match.data() - data + match.size();
|
|
422
|
+
lastIndex = offset + match.size();
|
|
423
|
+
}
|
|
424
|
+
else if (offset < size)
|
|
425
|
+
{
|
|
426
|
+
auto sym_size = getUtf8CharSize(data[offset]);
|
|
427
|
+
result.append(data + offset, sym_size);
|
|
428
|
+
lastIndex = offset + sym_size;
|
|
416
429
|
}
|
|
417
430
|
else
|
|
418
431
|
{
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
{
|
|
422
|
-
return part;
|
|
423
|
-
}
|
|
424
|
-
result += part.FromJust();
|
|
425
|
-
size_t sym_size = getUtf8CharSize(data[lastIndex]);
|
|
426
|
-
if (lastIndex < size)
|
|
427
|
-
{
|
|
428
|
-
result.append(data + lastIndex, sym_size);
|
|
429
|
-
}
|
|
430
|
-
lastIndex += sym_size;
|
|
432
|
+
lastIndex = size;
|
|
433
|
+
break;
|
|
431
434
|
}
|
|
432
435
|
if (!re2->global)
|
|
433
436
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "re2",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.4",
|
|
4
4
|
"description": "Bindings for RE2: fast, safe alternative to backtracking regular expression engines.",
|
|
5
5
|
"homepage": "https://github.com/uhop/node-re2",
|
|
6
6
|
"bugs": "https://github.com/uhop/node-re2/issues",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"test": "tests"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"install-artifact-from-github": "^1.
|
|
13
|
+
"install-artifact-from-github": "^1.3.0",
|
|
14
14
|
"nan": "^2.15.0",
|
|
15
15
|
"node-gyp": "^8.4.1"
|
|
16
16
|
},
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"test": "node tests/tests.js",
|
|
22
22
|
"save-to-github": "save-to-github-cache --artifact build/Release/re2.node",
|
|
23
|
-
"install": "install-from-cache --artifact build/Release/re2.node --host-var RE2_DOWNLOAD_MIRROR || npm run rebuild",
|
|
23
|
+
"install": "install-from-cache --artifact build/Release/re2.node --host-var RE2_DOWNLOAD_MIRROR --skip-path-var RE2_DOWNLOAD_SKIP_PATH --skip-ver-var RE2_DOWNLOAD_SKIP_VER || npm run rebuild",
|
|
24
24
|
"verify-build": "node scripts/verify-build.js",
|
|
25
25
|
"rebuild": "node-gyp rebuild"
|
|
26
26
|
},
|
|
@@ -35,6 +35,6 @@
|
|
|
35
35
|
"text processing",
|
|
36
36
|
"PCRE alternative"
|
|
37
37
|
],
|
|
38
|
-
"author": "Eugene Lazutkin <eugene.lazutkin@gmail.com> (
|
|
38
|
+
"author": "Eugene Lazutkin <eugene.lazutkin@gmail.com> (https://lazutkin.com/)",
|
|
39
39
|
"license": "BSD-3-Clause"
|
|
40
40
|
}
|