diff options
author | daurnimator <quae@daurnimator.com> | 2017-11-12 19:03:11 +1100 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-11-12 20:33:23 +1100 |
commit | 925b6007397058ac2440571942aeb1d913788fea (patch) | |
tree | 296ee8f7601d39ff17fbcddfecee909e025f4ac9 /src/lobject.js | |
parent | bb79aab60a40e485d144bfac10d70fbe213eb30c (diff) | |
download | fengari-925b6007397058ac2440571942aeb1d913788fea.tar.gz fengari-925b6007397058ac2440571942aeb1d913788fea.tar.bz2 fengari-925b6007397058ac2440571942aeb1d913788fea.zip |
src/lobject.js: Add try/catch around to_jsstring call in number coercions
Diffstat (limited to 'src/lobject.js')
-rw-r--r-- | src/lobject.js | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/lobject.js b/src/lobject.js index 9263cb1..8754e20 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -411,11 +411,15 @@ const lua_strx2number = function(s) { }; const lua_str2number = function(s) { + try { + s = defs.to_jsstring(s); + } catch (e) { + return null; + } /* parseFloat ignores trailing junk, validate with regex first */ - let str = defs.to_jsstring(s); - if (!/^[\t\v\f \n\r]*[\+\-]?([0-9]+\.?[0-9]*|\.[0-9]*)([eE][\+\-]?[0-9]+)?[\t\v\f \n\r]*$/.test(str)) + if (!/^[\t\v\f \n\r]*[\+\-]?([0-9]+\.?[0-9]*|\.[0-9]*)([eE][\+\-]?[0-9]+)?[\t\v\f \n\r]*$/.test(s)) return null; - let flt = parseFloat(str); + let flt = parseFloat(s); return !isNaN(flt) ? flt : null; }; |