re2 1.21.3 → 1.21.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 CHANGED
@@ -353,6 +353,7 @@ console.log('re2_res : ' + re2_res); // prints: re2_res : abc,a,b,c
353
353
 
354
354
  ## Release history
355
355
 
356
+ - 1.21.4 *Fixed a regression reported by [caroline-matsec](https://github.com/caroline-matsec), thx! Added pre-compilation targets for Alpine Linux on ARM. Updated deps.*
356
357
  - 1.21.3 *Fixed an empty string regression reported by [Rhys Arkins](https://github.com/rarkins), thx! Updated deps.*
357
358
  - 1.21.2 *Fixed another memory regression reported by [matthewvalentine](https://github.com/matthewvalentine), thx! Updated deps. Added more tests and benchmarks.*
358
359
  - 1.21.1 *Fixed a memory regression reported by [matthewvalentine](https://github.com/matthewvalentine), thx! Updated deps.*
package/lib/addon.cc CHANGED
@@ -116,6 +116,15 @@ const StrVal &WrappedRE2::prepareArgument(const v8::Local<v8::Value> &arg, bool
116
116
  {
117
117
  size_t startFrom = ignoreLastIndex ? 0 : lastIndex;
118
118
 
119
+ if (!lastString.IsEmpty())
120
+ {
121
+ lastString.ClearWeak();
122
+ }
123
+ if (!lastCache.IsEmpty())
124
+ {
125
+ lastCache.ClearWeak();
126
+ }
127
+
119
128
  if (lastString == arg && !node::Buffer::HasInstance(arg) && !lastCache.IsEmpty())
120
129
  {
121
130
  // we have a properly cached string
@@ -130,7 +139,6 @@ const StrVal &WrappedRE2::prepareArgument(const v8::Local<v8::Value> &arg, bool
130
139
  // no need to cache buffers
131
140
 
132
141
  lastString.Reset(arg);
133
- static_cast<v8::PersistentBase<v8::Value> &>(lastString).SetWeak();
134
142
 
135
143
  auto argSize = node::Buffer::Length(arg);
136
144
  lastStringValue.reset(arg, argSize, argSize, startFrom, true);
@@ -149,14 +157,12 @@ const StrVal &WrappedRE2::prepareArgument(const v8::Local<v8::Value> &arg, bool
149
157
  }
150
158
 
151
159
  lastString.Reset(arg);
152
- static_cast<v8::PersistentBase<v8::Value> &>(lastString).SetWeak();
153
160
 
154
161
  auto s = t.ToLocalChecked();
155
162
  auto argLength = Nan::DecodeBytes(s);
156
163
 
157
164
  auto buffer = node::Buffer::New(v8::Isolate::GetCurrent(), s).ToLocalChecked();
158
165
  lastCache.Reset(buffer);
159
- static_cast<v8::PersistentBase<v8::Object> &>(lastCache).SetWeak();
160
166
 
161
167
  auto argSize = node::Buffer::Length(buffer);
162
168
  lastStringValue.reset(buffer, argSize, argLength, startFrom);
@@ -164,6 +170,19 @@ const StrVal &WrappedRE2::prepareArgument(const v8::Local<v8::Value> &arg, bool
164
170
  return lastStringValue;
165
171
  };
166
172
 
173
+ void WrappedRE2::doneWithLastString()
174
+ {
175
+ if (!lastString.IsEmpty())
176
+ {
177
+ static_cast<v8::PersistentBase<v8::Value> &>(lastString).SetWeak();
178
+ }
179
+
180
+ if (!lastCache.IsEmpty())
181
+ {
182
+ static_cast<v8::PersistentBase<v8::Object> &>(lastCache).SetWeak();
183
+ }
184
+ }
185
+
167
186
  // StrVal
168
187
 
169
188
  void StrVal::setIndex(size_t newIndex)
package/lib/exec.cc CHANGED
@@ -14,7 +14,8 @@ NAN_METHOD(WrappedRE2::Exec)
14
14
  return;
15
15
  }
16
16
 
17
- auto str = re2->prepareArgument(info[0]);
17
+ PrepareLastString prep(re2, info[0]);
18
+ StrVal& str = prep;
18
19
  if (str.isBad) return; // throws an exception
19
20
 
20
21
  if (re2->global || re2->sticky)
package/lib/match.cc CHANGED
@@ -14,7 +14,8 @@ NAN_METHOD(WrappedRE2::Match)
14
14
  return;
15
15
  }
16
16
 
17
- auto str = re2->prepareArgument(info[0], re2->global);
17
+ PrepareLastString prep(re2, info[0]);
18
+ StrVal& str = prep;
18
19
  if (str.isBad) return; // throws an exception
19
20
 
20
21
  if (!str.isValidIndex)
package/lib/replace.cc CHANGED
@@ -497,7 +497,8 @@ NAN_METHOD(WrappedRE2::Replace)
497
497
  return;
498
498
  }
499
499
 
500
- auto replacee = re2->prepareArgument(info[0]);
500
+ PrepareLastString prep(re2, info[0]);
501
+ StrVal& replacee = prep;
501
502
  if (replacee.isBad) return; // throws an exception
502
503
 
503
504
  if (!replacee.isValidIndex)
package/lib/search.cc CHANGED
@@ -12,7 +12,8 @@ NAN_METHOD(WrappedRE2::Search)
12
12
  return;
13
13
  }
14
14
 
15
- auto str = re2->prepareArgument(info[0], true);
15
+ PrepareLastString prep(re2, info[0]);
16
+ StrVal& str = prep;
16
17
  if (str.isBad) return; // throws an exception
17
18
 
18
19
  if (!str.data)
package/lib/split.cc CHANGED
@@ -19,7 +19,8 @@ NAN_METHOD(WrappedRE2::Split)
19
19
  return;
20
20
  }
21
21
 
22
- auto str = re2->prepareArgument(info[0], true);
22
+ PrepareLastString prep(re2, info[0]);
23
+ StrVal& str = prep;
23
24
  if (str.isBad) return; // throws an exception
24
25
 
25
26
  size_t limit = std::numeric_limits<size_t>::max();
package/lib/test.cc CHANGED
@@ -14,7 +14,8 @@ NAN_METHOD(WrappedRE2::Test)
14
14
  return;
15
15
  }
16
16
 
17
- auto str = re2->prepareArgument(info[0]);
17
+ PrepareLastString prep(re2, info[0]);
18
+ StrVal& str = prep;
18
19
  if (str.isBad) return; // throws an exception
19
20
 
20
21
  if (!re2->global && !re2->sticky)
package/lib/wrapped_re2.h CHANGED
@@ -119,6 +119,30 @@ private:
119
119
 
120
120
  void dropCache();
121
121
  const StrVal &prepareArgument(const v8::Local<v8::Value> &arg, bool ignoreLastIndex = false);
122
+ void doneWithLastString();
123
+
124
+ friend class PrepareLastString;
125
+ };
126
+
127
+ struct PrepareLastString
128
+ {
129
+ PrepareLastString(WrappedRE2 *re2, const v8::Local<v8::Value> &arg, bool ignoreLastIndex = false) : re2(re2) {
130
+ re2->prepareArgument(arg, ignoreLastIndex);
131
+ }
132
+
133
+ ~PrepareLastString() {
134
+ re2->doneWithLastString();
135
+ }
136
+
137
+ operator const StrVal&() const {
138
+ return re2->lastStringValue;
139
+ }
140
+
141
+ operator StrVal&() {
142
+ return re2->lastStringValue;
143
+ }
144
+
145
+ WrappedRE2 *re2;
122
146
  };
123
147
 
124
148
  // utilities
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "re2",
3
- "version": "1.21.3",
3
+ "version": "1.21.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",
@@ -17,12 +17,12 @@
17
17
  "dependencies": {
18
18
  "install-artifact-from-github": "^1.3.5",
19
19
  "nan": "^2.20.0",
20
- "node-gyp": "^10.1.0"
20
+ "node-gyp": "^10.2.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@types/node": "^20.14.2",
23
+ "@types/node": "^22.5.0",
24
24
  "heya-unit": "^0.3.0",
25
- "typescript": "^5.4.5"
25
+ "typescript": "^5.5.4"
26
26
  },
27
27
  "scripts": {
28
28
  "test": "node tests/tests.js",