From 925b6007397058ac2440571942aeb1d913788fea Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sun, 12 Nov 2017 19:03:11 +1100 Subject: src/lobject.js: Add try/catch around to_jsstring call in number coercions --- src/lobject.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') 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; }; -- cgit v1.2.3-70-g09d2