re2 1.19.0 → 1.19.2

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 CHANGED
@@ -54,11 +54,11 @@ Supported properties:
54
54
  * [`re2.global`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
55
55
  * [`re2.ignoreCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
56
56
  * [`re2.multiline`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
57
- * *Since 1.17.6*: [`re2.dotAll`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/dotAll)
57
+ * [`re2.dotAll`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/dotAll) — *since 1.17.6.*
58
58
  * [`re2.unicode`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode)
59
59
  * `RE2` engine always works in the Unicode mode. See details below.
60
- * [`re2.sticky`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
61
- * *Since 1.19.0*: [`re2.hasIndices`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices)
60
+ * [`re2.sticky`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky) — *since 1.7.0.*
61
+ * [`re2.hasIndices`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices) — *since 1.19.0.*
62
62
  * [`re2.source`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
63
63
  * [`re2.flags`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
64
64
 
@@ -71,7 +71,7 @@ Supported methods:
71
71
  Starting with 1.6.0 following well-known symbol-based methods are supported (see [Symbols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)):
72
72
 
73
73
  * [`re2[Symbol.match](str)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
74
- * *Since 1.17.5*: [`re2[Symbol.matchAll](str)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/matchAll)
74
+ * [`re2[Symbol.matchAll](str)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/matchAll) — *since 1.17.5.*
75
75
  * [`re2[Symbol.search](str)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
76
76
  * [`re2[Symbol.replace](str, newSubStr|function)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
77
77
  * [`re2[Symbol.split](str[, limit])`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
@@ -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.19.2 *Bugfix: infinite loop in matchAll() with empty matches. Thx, [ziyunfei](https://github.com/ziyunfei).*
357
+ - 1.19.1 *Bugfix: indices for the `d` flag when `lastIndex` is non zero. Bugfix: the match result. Thx, [teebu](https://github.com/teebu).*
356
358
  - 1.19.0 *Added `hasIndices` AKA the `d` flag. Thx, [teebu](https://github.com/teebu).*
357
359
  - 1.18.3 *Fixed bug with non-matched groups. Thx, [Dan Setterquist](https://github.com/dset).*
358
360
  - 1.18.2 *Reference to the binary module by its full name.*
package/lib/exec.cc CHANGED
@@ -90,8 +90,8 @@ NAN_METHOD(WrappedRE2::Exec)
90
90
  if (re2->hasIndices) {
91
91
  auto pair = Nan::New<v8::Array>();
92
92
  auto offset = data - str.data;
93
- Nan::Set(pair, 0, Nan::New<v8::Integer>(static_cast<int>(offset)));
94
- Nan::Set(pair, 1, Nan::New<v8::Integer>(static_cast<int>(offset + item.size())));
93
+ Nan::Set(pair, 0, Nan::New<v8::Integer>(indexOffset + static_cast<int>(offset)));
94
+ Nan::Set(pair, 1, Nan::New<v8::Integer>(indexOffset + static_cast<int>(offset + item.size())));
95
95
  Nan::Set(indices, i, pair);
96
96
  }
97
97
  }
@@ -118,8 +118,8 @@ NAN_METHOD(WrappedRE2::Exec)
118
118
  auto pair = Nan::New<v8::Array>();
119
119
  auto offset = getUtf16Length(str.data + lastIndex, data);
120
120
  auto length = getUtf16Length(data, data + item.size());
121
- Nan::Set(pair, 0, Nan::New<v8::Integer>(static_cast<int>(offset)));
122
- Nan::Set(pair, 1, Nan::New<v8::Integer>(static_cast<int>(offset + length)));
121
+ Nan::Set(pair, 0, Nan::New<v8::Integer>(indexOffset + static_cast<int>(offset)));
122
+ Nan::Set(pair, 1, Nan::New<v8::Integer>(indexOffset + static_cast<int>(offset + length)));
123
123
  Nan::Set(indices, i, pair);
124
124
  }
125
125
  }
package/lib/match.cc CHANGED
@@ -206,11 +206,10 @@ NAN_METHOD(WrappedRE2::Match)
206
206
  Nan::Set(indices, Nan::New("groups").ToLocalChecked(), Nan::Undefined());
207
207
  }
208
208
  }
209
- }
210
-
211
- if (re2->hasIndices)
212
- {
213
- Nan::Set(result, Nan::New("indices").ToLocalChecked(), indices);
209
+ if (re2->hasIndices)
210
+ {
211
+ Nan::Set(result, Nan::New("indices").ToLocalChecked(), indices);
212
+ }
214
213
  }
215
214
 
216
215
  info.GetReturnValue().Set(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "re2",
3
- "version": "1.19.0",
3
+ "version": "1.19.2",
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",
@@ -13,12 +13,12 @@
13
13
  "dependencies": {
14
14
  "install-artifact-from-github": "^1.3.3",
15
15
  "nan": "^2.17.0",
16
- "node-gyp": "^9.3.1"
16
+ "node-gyp": "^9.4.0"
17
17
  },
18
18
  "devDependencies": {
19
- "@types/node": "^20.2.3",
19
+ "@types/node": "^20.4.5",
20
20
  "heya-unit": "^0.3.0",
21
- "typescript": "^5.0.4"
21
+ "typescript": "^5.1.6"
22
22
  },
23
23
  "scripts": {
24
24
  "test": "node tests/tests.js",
package/re2.js CHANGED
@@ -29,6 +29,7 @@ if (typeof Symbol != 'undefined') {
29
29
  for (;;) {
30
30
  const result = re.exec(str);
31
31
  if (!result) break;
32
+ if (result[0] === '') ++re.lastIndex;
32
33
  yield result;
33
34
  }
34
35
  });
@@ -414,5 +414,27 @@ xy2 (at start of line)
414
414
  } catch (e) {
415
415
  // squelch
416
416
  }
417
+ },
418
+
419
+ function test_hasIndexLastIndex(t) {
420
+ 'use strict';
421
+
422
+ const re2 = new RE2('a', 'dg');
423
+
424
+ eval(t.TEST('re2.lastIndex === 0'));
425
+
426
+ let result = re2.exec('abca');
427
+ eval(t.TEST('re2.lastIndex === 1'));
428
+ eval(t.TEST('result.index === 0'));
429
+ eval(t.TEST('t.unify(result.indices, [[0, 1]])'));
430
+
431
+ result = re2.exec('abca');
432
+ eval(t.TEST('re2.lastIndex === 4'));
433
+ eval(t.TEST('result.index === 3'));
434
+ eval(t.TEST('t.unify(result.indices, [[3, 4]])'));
435
+
436
+ result = re2.exec('abca');
437
+ eval(t.TEST('re2.lastIndex === 0'));
438
+ eval(t.TEST('result === null'));
417
439
  }
418
440
  ]);
@@ -151,11 +151,22 @@ unit.add(module, [
151
151
  function test_matchHasIndices(t) {
152
152
  'use strict';
153
153
 
154
- var re = new RE2('(aa)(?<b>b)?(?<c>ccc)', 'd'),
154
+ const re = new RE2('(aa)(?<b>b)?(?<c>ccc)', 'd'),
155
155
  str1 = '1aabccc2',
156
156
  str2 = '1aaccc2';
157
157
 
158
158
  eval(t.TEST("t.unify(str1.match(re), re.exec(str1))"));
159
159
  eval(t.TEST("t.unify(str2.match(re), re.exec(str2))"));
160
+ },
161
+
162
+ function test_matchHasIndicesGlobal(t) {
163
+ 'use strict';
164
+
165
+ const re = new RE2('(?<zzz>a)', 'dg'),
166
+ result = 'abca'.match(re);
167
+
168
+ eval(t.TEST("t.unify(result, ['a', 'a'])"));
169
+ eval(t.TEST("!('indices' in result)"));
170
+ eval(t.TEST("!('groups' in result)"));
160
171
  }
161
172
  ]);
@@ -77,5 +77,19 @@ unit.add(module, [
77
77
  eval(t.TEST('match[0] === expected[i]'));
78
78
  ++i;
79
79
  }
80
+ },
81
+
82
+ function test_matchAll_empty_match(t) {
83
+ 'use strict';
84
+
85
+ const str = 'foo';
86
+ // Matches empty strings, but should not cause an infinite loop
87
+ const re = new RE2('(?:)', 'g');
88
+ const result = Array.from(str.matchAll(re));
89
+
90
+ eval(t.TEST('result.length === str.length + 1'));
91
+ for (let i = 0; i < result.length; ++i) {
92
+ eval(t.TEST('result[i][0] === ""'));
93
+ }
80
94
  }
81
95
  ]);