From 29445c09adc02dcf2f904bdb589bd7cb2b2931b5 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Sat, 13 May 2017 20:32:47 +0200 Subject: Removed useless save(0) in llex --- src/llex.js | 2 +- tests/test-suite/literals.js | 65 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/llex.js b/src/llex.js index 2e37eca..0825146 100644 --- a/src/llex.js +++ b/src/llex.js @@ -315,7 +315,7 @@ const txtToken = function(ls, token) { switch (token) { case R.TK_NAME: case R.TK_STRING: case R.TK_FLT: case R.TK_INT: - save(ls, 0); + // save(ls, 0); return defs.to_luastring(`'${defs.to_jsstring(ls.buff.buffer)}'`); default: return luaX_token2str(ls, token); diff --git a/tests/test-suite/literals.js b/tests/test-suite/literals.js index fa11959..8dac1fa 100644 --- a/tests/test-suite/literals.js +++ b/tests/test-suite/literals.js @@ -184,3 +184,68 @@ test("[test-suite] events: UTF-8 sequences", function (t) { }); + +test("[test-suite] events: Error in escape sequences", function (t) { + let luaCode = ` + local function lexerror (s, err) + local st, msg = load('return ' .. s, '') + if err ~= '' then err = err .. "'" end + assert(not st and string.find(msg, "near .-" .. err)) + end + + lexerror([["abc\\x"]], [[\\x"]]) + lexerror([["abc\\x]], [[\\x]]) + lexerror([["\\x]], [[\\x]]) + lexerror([["\\x5"]], [[\\x5"]]) + lexerror([["\\x5]], [[\\x5]]) + lexerror([["\\xr"]], [[\\xr]]) + lexerror([["\\xr]], [[\\xr]]) + lexerror([["\\x.]], [[\\x.]]) + lexerror([["\\x8%"]], [[\\x8%%]]) + lexerror([["\\xAG]], [[\\xAG]]) + lexerror([["\\g"]], [[\\g]]) + lexerror([["\\g]], [[\\g]]) + lexerror([["\\."]], [[\\%.]]) + + lexerror([["\\999"]], [[\\999"]]) + lexerror([["xyz\\300"]], [[\\300"]]) + lexerror([[" \\256"]], [[\\256"]]) + + -- errors in UTF-8 sequences + lexerror([["abc\\u{110000}"]], [[abc\\u{110000]]) -- too large + lexerror([["abc\\u11r"]], [[abc\\u1]]) -- missing '{' + lexerror([["abc\\u"]], [[abc\\u"]]) -- missing '{' + lexerror([["abc\\u{11r"]], [[abc\\u{11r]]) -- missing '}' + lexerror([["abc\\u{11"]], [[abc\\u{11"]]) -- missing '}' + lexerror([["abc\\u{11]], [[abc\\u{11]]) -- missing '}' + lexerror([["abc\\u{r"]], [[abc\\u{r]]) -- no digits + + -- unfinished strings + lexerror("[=[alo]]", "") + lexerror("[=[alo]=", "") + lexerror("[=[alo]", "") + lexerror("'alo", "") + lexerror("'alo \\\\z \\n\\n", "") + lexerror("'alo \\\\z", "") + lexerror([['alo \\98]], "") + `, L; + + t.plan(2); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + lualib.luaL_openlibs(L); + + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); + + }, "Lua program loaded without error"); + + t.doesNotThrow(function () { + + lua.lua_call(L, 0, -1); + + }, "Lua program ran without error"); + +}); \ No newline at end of file -- cgit v1.2.3-70-g09d2