From f7550508fef2ae2f6c64b1f5f359af5f65bb62fd Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 21 May 2017 20:49:22 +1000 Subject: src/lobject.js: Check that there is no trailing junk from lua_strx2number Also stop adding trailing null byte in llex.js --- src/llex.js | 2 +- src/lobject.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/llex.js b/src/llex.js index d617e7c..998ab0e 100644 --- a/src/llex.js +++ b/src/llex.js @@ -240,7 +240,7 @@ const read_numeral = function(ls, seminfo) { else break; } - save(ls, 0); + // save(ls, 0); let obj = lobject.luaO_str2num(ls.buff.buffer); if (obj === false) /* format error? */ diff --git a/src/lobject.js b/src/lobject.js index 0898a15..153d776 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -346,7 +346,8 @@ const lua_strx2number = function(s) { e += exp1; } if (neg) r = -r; - return defs.to_jsstring(s).trim().search(/s/) < 0 ? luaconf.ldexp(r, e) : null; /* Only valid if nothing left is s*/ + while (ljstype.lisspace(s[0])) s = s.slice(1); /* skip trailing spaces */ + return s.length === 0 ? luaconf.ldexp(r, e) : null; /* Only valid if nothing left is s*/ }; const l_str2dloc = function(s, mode) { @@ -401,7 +402,7 @@ const l_str2int = function(s) { while (ljstype.lisspace(s[0])) s = s.slice(1); /* skip trailing spaces */ - if (empty || (s.length > 0 && s[0] !== 0)) return null; /* something wrong in the numeral */ + if (empty || (s.length !== 0)) return null; /* something wrong in the numeral */ else { return (neg ? -a : a)|0; } -- cgit v1.2.3-70-g09d2