re2 1.17.0 → 1.17.1

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
@@ -343,6 +343,7 @@ console.log('re2_res : ' + re2_res); // prints: re2_res : abc,a,b,c
343
343
 
344
344
  ## Release history
345
345
 
346
+ - 1.17.1 *Fix for `lastIndex` for U+10000 - U+10FFFF UTF characters. Thx, [omg](https://github.com/omg).*
346
347
  - 1.17.0 *Updated GYP, added support for Node 17, updated deps.*
347
348
  - 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)).*
348
349
  - 1.15.9 *Updated deps.*
package/lib/exec.cc CHANGED
@@ -50,7 +50,10 @@ NAN_METHOD(WrappedRE2::Exec)
50
50
  }
51
51
  for (size_t n = re2->lastIndex; n; --n)
52
52
  {
53
- lastIndex += getUtf8CharSize(str.data[lastIndex]);
53
+ size_t s = getUtf8CharSize(str.data[lastIndex]);
54
+ lastIndex += s;
55
+ if (s == 4 && n >= 2) --n; // this utf8 character will take two utf16 characters
56
+ // the decrement above is protected to avoid an overflow of an unsigned integer
54
57
  }
55
58
  }
56
59
  }
package/lib/match.cc CHANGED
@@ -59,7 +59,10 @@ NAN_METHOD(WrappedRE2::Match)
59
59
  {
60
60
  for (size_t n = re2->lastIndex; n; --n)
61
61
  {
62
- lastIndex += getUtf8CharSize(a.data[lastIndex]);
62
+ size_t s = getUtf8CharSize(a.data[lastIndex]);
63
+ lastIndex += s;
64
+ if (s == 4 && n >= 2) --n; // this utf8 character will take two utf16 characters
65
+ // the decrement above is protected to avoid an overflow of an unsigned integer
63
66
  }
64
67
  anchor = RE2::ANCHOR_START;
65
68
  }
package/lib/replace.cc CHANGED
@@ -226,7 +226,10 @@ static Nan::Maybe<std::string> replace(WrappedRE2 *re2, const StrVal &replacee,
226
226
  {
227
227
  for (size_t n = re2->lastIndex; n; --n)
228
228
  {
229
- lastIndex += getUtf8CharSize(data[lastIndex]);
229
+ size_t s = getUtf8CharSize(data[lastIndex]);
230
+ lastIndex += s;
231
+ if (s == 4 && n >= 2) --n; // this utf8 character will take two utf16 characters
232
+ // the decrement above is protected to avoid an overflow of an unsigned integer
230
233
  }
231
234
  }
232
235
  }
@@ -372,7 +375,10 @@ static Nan::Maybe<std::string> replace(WrappedRE2 *re2, const StrVal &replacee,
372
375
  {
373
376
  for (size_t n = re2->lastIndex; n; --n)
374
377
  {
375
- lastIndex += getUtf8CharSize(data[lastIndex]);
378
+ size_t s = getUtf8CharSize(data[lastIndex]);
379
+ lastIndex += s;
380
+ if (s == 4 && n >= 2) --n; // this utf8 character will take two utf16 characters
381
+ // the decrement above is protected to avoid an overflow of an unsigned integer
376
382
  }
377
383
  }
378
384
  }
package/lib/test.cc CHANGED
@@ -50,7 +50,10 @@ NAN_METHOD(WrappedRE2::Test)
50
50
  }
51
51
  for (size_t n = re2->lastIndex; n; --n)
52
52
  {
53
- lastIndex += getUtf8CharSize(str.data[lastIndex]);
53
+ size_t s = getUtf8CharSize(str.data[lastIndex]);
54
+ lastIndex += s;
55
+ if (s == 4 && n >= 2) --n; // this utf8 character will take two utf16 characters
56
+ // the decrement above is protected to avoid an overflow of an unsigned integer
54
57
  }
55
58
  }
56
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "re2",
3
- "version": "1.17.0",
3
+ "version": "1.17.1",
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",
@@ -284,6 +284,22 @@ unit.add(module, [
284
284
  eval(t.TEST("re2.lastIndex === 6"));
285
285
  },
286
286
 
287
+ function test_execSupplemental(t) {
288
+ "use strict";
289
+
290
+ var re = new RE2("\\w+", "g");
291
+ var testString = "🤡🤡🤡 Hello clown world!";
292
+
293
+ var result = re.exec(testString);
294
+ eval(t.TEST("t.unify(result, ['Hello'])"));
295
+
296
+ result = re.exec(testString);
297
+ eval(t.TEST("t.unify(result, ['clown'])"));
298
+
299
+ result = re.exec(testString);
300
+ eval(t.TEST("t.unify(result, ['world'])"));
301
+ },
302
+
287
303
  // Multiline test
288
304
 
289
305
  function test_execMultiline(t) {