summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/llex.js2
-rw-r--r--tests/test-suite/literals.js65
2 files changed, 66 insertions, 1 deletions
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 ~= '<eof>' 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]]", "<eof>")
+ lexerror("[=[alo]=", "<eof>")
+ lexerror("[=[alo]", "<eof>")
+ lexerror("'alo", "<eof>")
+ lexerror("'alo \\\\z \\n\\n", "<eof>")
+ lexerror("'alo \\\\z", "<eof>")
+ lexerror([['alo \\98]], "<eof>")
+ `, 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