re2 1.20.2 → 1.20.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 +2 -0
- package/lib/new.cc +25 -15
- package/lib/replace.cc +6 -0
- package/package.json +4 -4
- package/tests/test_general.js +39 -0
- package/tests/test_replace.js +42 -0
package/README.md
CHANGED
|
@@ -353,6 +353,8 @@ console.log('re2_res : ' + re2_res); // prints: re2_res : abc,a,b,c
|
|
|
353
353
|
|
|
354
354
|
## Release history
|
|
355
355
|
|
|
356
|
+
- 1.20.4 *Updated deps. Fix: the 2nd argument of the constructor overrides flags. Thx, [gost-serb](https://github.com/gost-serb).*
|
|
357
|
+
- 1.20.3 *Fix: subsequent numbers are incorporated into group if they would form a legal group reference. Thx, [Oleksii Vasyliev](https://github.com/le0pard).*
|
|
356
358
|
- 1.20.2 *Fix: added a missing C++ file, which caused a bug on Alpine Linux. Thx, [rbitanga-manticore](https://github.com/rbitanga-manticore).*
|
|
357
359
|
- 1.20.1 *Fix: files included in the npm package to build the C++ code.*
|
|
358
360
|
- 1.20.0 *Updated RE2. New version uses `abseil-cpp` and required the adaptation work. Thx, [Stefano Rivera](https://github.com/stefanor).*
|
package/lib/new.cc
CHANGED
|
@@ -235,6 +235,7 @@ NAN_METHOD(WrappedRE2::New)
|
|
|
235
235
|
bool hasIndices = false;
|
|
236
236
|
|
|
237
237
|
auto context = Nan::GetCurrentContext();
|
|
238
|
+
bool needFlags = true;
|
|
238
239
|
|
|
239
240
|
if (info.Length() > 1)
|
|
240
241
|
{
|
|
@@ -279,6 +280,7 @@ NAN_METHOD(WrappedRE2::New)
|
|
|
279
280
|
}
|
|
280
281
|
}
|
|
281
282
|
size = 0;
|
|
283
|
+
needFlags = false;
|
|
282
284
|
}
|
|
283
285
|
|
|
284
286
|
bool needConversion = true;
|
|
@@ -303,14 +305,18 @@ NAN_METHOD(WrappedRE2::New)
|
|
|
303
305
|
|
|
304
306
|
source = escapeRegExp(data, size);
|
|
305
307
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
308
|
+
if (needFlags)
|
|
309
|
+
{
|
|
310
|
+
v8::RegExp::Flags flags = re->GetFlags();
|
|
311
|
+
global = bool(flags & v8::RegExp::kGlobal);
|
|
312
|
+
ignoreCase = bool(flags & v8::RegExp::kIgnoreCase);
|
|
313
|
+
multiline = bool(flags & v8::RegExp::kMultiline);
|
|
314
|
+
dotAll = bool(flags & v8::RegExp::kDotAll);
|
|
315
|
+
unicode = bool(flags & v8::RegExp::kUnicode);
|
|
316
|
+
sticky = bool(flags & v8::RegExp::kSticky);
|
|
317
|
+
hasIndices = bool(flags & v8::RegExp::kHasIndices);
|
|
318
|
+
needFlags = false;
|
|
319
|
+
}
|
|
314
320
|
}
|
|
315
321
|
else if (info[0]->IsObject() && !info[0]->IsString())
|
|
316
322
|
{
|
|
@@ -331,13 +337,17 @@ NAN_METHOD(WrappedRE2::New)
|
|
|
331
337
|
|
|
332
338
|
source = re2->source;
|
|
333
339
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
340
|
+
if (needFlags)
|
|
341
|
+
{
|
|
342
|
+
global = re2->global;
|
|
343
|
+
ignoreCase = re2->ignoreCase;
|
|
344
|
+
multiline = re2->multiline;
|
|
345
|
+
dotAll = re2->dotAll;
|
|
346
|
+
unicode = true;
|
|
347
|
+
sticky = re2->sticky;
|
|
348
|
+
hasIndices = re2->hasIndices;
|
|
349
|
+
needFlags = false;
|
|
350
|
+
}
|
|
341
351
|
}
|
|
342
352
|
}
|
|
343
353
|
else if (info[0]->IsString())
|
package/lib/replace.cc
CHANGED
|
@@ -142,6 +142,12 @@ inline std::string replace(const char *data, size_t size, const std::vector<re2:
|
|
|
142
142
|
result += (std::string)groups[index2];
|
|
143
143
|
continue;
|
|
144
144
|
}
|
|
145
|
+
else if (index && index < groups.size())
|
|
146
|
+
{
|
|
147
|
+
result += (std::string)groups[index];
|
|
148
|
+
result += ch;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
145
151
|
result += '$';
|
|
146
152
|
result += '0' + index;
|
|
147
153
|
result += ch;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "re2",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.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",
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"install-artifact-from-github": "^1.3.3",
|
|
15
|
-
"nan": "^2.
|
|
15
|
+
"nan": "^2.18.0",
|
|
16
16
|
"node-gyp": "^9.4.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@types/node": "^20.
|
|
19
|
+
"@types/node": "^20.8.7",
|
|
20
20
|
"heya-unit": "^0.3.0",
|
|
21
|
-
"typescript": "^5.
|
|
21
|
+
"typescript": "^5.2.2"
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
24
|
"test": "node tests/tests.js",
|
package/tests/test_general.js
CHANGED
|
@@ -278,6 +278,45 @@ unit.add(module, [
|
|
|
278
278
|
|
|
279
279
|
re = new RE2("a", "smigyu");
|
|
280
280
|
eval(t.TEST("re.flags === 'gimsuy'"));
|
|
281
|
+
},
|
|
282
|
+
function test_flags_2nd(t) {
|
|
283
|
+
"use strict";
|
|
284
|
+
|
|
285
|
+
var re = new RE2(/a/, "u");
|
|
286
|
+
eval(t.TEST("re.flags === 'u'"));
|
|
287
|
+
|
|
288
|
+
re = new RE2(/a/gm, "iu");
|
|
289
|
+
eval(t.TEST("re.flags === 'iu'"));
|
|
290
|
+
|
|
291
|
+
re = new RE2(/a/ig, "mu");
|
|
292
|
+
eval(t.TEST("re.flags === 'mu'"));
|
|
293
|
+
|
|
294
|
+
re = new RE2(/a/g, "gu");
|
|
295
|
+
eval(t.TEST("re.flags === 'gu'"));
|
|
296
|
+
|
|
297
|
+
re = new RE2(/a/m, "yu");
|
|
298
|
+
eval(t.TEST("re.flags === 'uy'"));
|
|
299
|
+
|
|
300
|
+
re = new RE2(/a/, "yiu");
|
|
301
|
+
eval(t.TEST("re.flags === 'iuy'"));
|
|
302
|
+
|
|
303
|
+
re = new RE2(/a/gim, "yigu");
|
|
304
|
+
eval(t.TEST("re.flags === 'giuy'"));
|
|
305
|
+
|
|
306
|
+
re = new RE2(/a/gm, "miu");
|
|
307
|
+
eval(t.TEST("re.flags === 'imu'"));
|
|
308
|
+
|
|
309
|
+
re = new RE2(/a/i, "ygu");
|
|
310
|
+
eval(t.TEST("re.flags === 'guy'"));
|
|
311
|
+
|
|
312
|
+
re = new RE2(/a/g, "myu");
|
|
313
|
+
eval(t.TEST("re.flags === 'muy'"));
|
|
314
|
+
|
|
315
|
+
re = new RE2(/a/, "migyu");
|
|
316
|
+
eval(t.TEST("re.flags === 'gimuy'"));
|
|
317
|
+
|
|
318
|
+
re = new RE2(/a/s, "smigyu");
|
|
319
|
+
eval(t.TEST("re.flags === 'gimsuy'"));
|
|
281
320
|
}
|
|
282
321
|
]);
|
|
283
322
|
|
package/tests/test_replace.js
CHANGED
|
@@ -334,5 +334,47 @@ unit.add(module, [
|
|
|
334
334
|
var re = new RE2(/b(?<a>1)? & (?<b>2)?y/);
|
|
335
335
|
var result = re.replace('ab & yz', replacer);
|
|
336
336
|
eval(t.TEST("result === 'az'"));
|
|
337
|
+
},
|
|
338
|
+
function test_replaceGroupSimple(t) {
|
|
339
|
+
'use strict';
|
|
340
|
+
|
|
341
|
+
var re = new RE2(/(2)/);
|
|
342
|
+
|
|
343
|
+
var result = re.replace('123', '$0');
|
|
344
|
+
eval(t.TEST("result === '1$03'"));
|
|
345
|
+
result = re.replace('123', '$1');
|
|
346
|
+
eval(t.TEST("result === '123'"));
|
|
347
|
+
result = re.replace('123', '$2');
|
|
348
|
+
eval(t.TEST("result === '1$23'"));
|
|
349
|
+
|
|
350
|
+
result = re.replace('123', '$00');
|
|
351
|
+
eval(t.TEST("result === '1$003'"));
|
|
352
|
+
result = re.replace('123', '$01');
|
|
353
|
+
eval(t.TEST("result === '123'"));
|
|
354
|
+
result = re.replace('123', '$02');
|
|
355
|
+
eval(t.TEST("result === '1$023'"));
|
|
356
|
+
},
|
|
357
|
+
function test_replaceGroupCases(t) {
|
|
358
|
+
'use strict';
|
|
359
|
+
|
|
360
|
+
var re = new RE2(/(test)/g);
|
|
361
|
+
var result = re.replace('123', '$1$20');
|
|
362
|
+
eval(t.TEST("result === '123'"));
|
|
363
|
+
|
|
364
|
+
re = new RE2(/(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)/g);
|
|
365
|
+
result = re.replace('abcdefghijklmnopqrstuvwxyz123', '$10$20');
|
|
366
|
+
eval(t.TEST("result === 'jb0wo0123'"));
|
|
367
|
+
|
|
368
|
+
re = new RE2(/(.)(.)(.)(.)(.)/g);
|
|
369
|
+
result = re.replace('abcdefghijklmnopqrstuvwxyz123', '$10$20');
|
|
370
|
+
eval(t.TEST("result === 'a0b0f0g0k0l0p0q0u0v0z123'"));
|
|
371
|
+
|
|
372
|
+
re = new RE2(/(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)/g);
|
|
373
|
+
result = re.replace('abcdefghijklmnopqrstuvwxyz123', '$10$20');
|
|
374
|
+
eval(t.TEST("result === 'jtvwxyz123'"));
|
|
375
|
+
|
|
376
|
+
re = new RE2(/abcd/g);
|
|
377
|
+
result = re.replace('abcd123', '$1$2');
|
|
378
|
+
eval(t.TEST("result === '$1$2123'"));
|
|
337
379
|
}
|
|
338
380
|
]);
|