summaryrefslogtreecommitdiff
path: root/src/lstrlib.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-06-15 01:10:39 +1000
committerdaurnimator <quae@daurnimator.com>2017-06-15 01:10:39 +1000
commit5fb9e658f0e9a1604ae4314ba531179e1cfbd8bb (patch)
treebc0bbc0efd10655f8fe59433c38c743296ce610f /src/lstrlib.js
parent42aec0363191bf38832586af50ee22fbd4df47a3 (diff)
downloadfengari-5fb9e658f0e9a1604ae4314ba531179e1cfbd8bb.tar.gz
fengari-5fb9e658f0e9a1604ae4314ba531179e1cfbd8bb.tar.bz2
fengari-5fb9e658f0e9a1604ae4314ba531179e1cfbd8bb.zip
src/lstrlib.js: In match_capture compare array contents not array slices
Diffstat (limited to 'src/lstrlib.js')
-rw-r--r--src/lstrlib.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/lstrlib.js b/src/lstrlib.js
index d0d1646..70b9e5f 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -986,10 +986,20 @@ const end_capture = function(ms, s, p) {
return res;
};
+/* Compare the elements of arrays 'a' and 'b' to see if they contain the same elements */
+const array_cmp = function(a, ai, b, bi, len) {
+ let aj = ai+len;
+ for (; ai < aj; ai++, bi++) {
+ if (a[ai] !== b[bi])
+ return false;
+ }
+ return true;
+};
+
const match_capture = function(ms, s, l) {
l = check_capture(ms, l);
let len = ms.capture[l].len;
- if (ms.src_end >= len && ms.src.slice(ms.capture[l].init, ms.capture[l].init + len) === ms.src.slice(s, s + len))
+ if ((ms.src_end-s) >= len && array_cmp(ms.src, ms.capture[l].init, ms.src, s, len))
return s+len;
else return null;
};