From 5fb9e658f0e9a1604ae4314ba531179e1cfbd8bb Mon Sep 17 00:00:00 2001 From: daurnimator Date: Thu, 15 Jun 2017 01:10:39 +1000 Subject: src/lstrlib.js: In match_capture compare array contents not array slices --- src/lstrlib.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') 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; }; -- cgit v1.2.3-54-g00ecf