From 795c86a5aefe8c45cc934a525772b22f65a1c134 Mon Sep 17 00:00:00 2001 From: NiteHawk Date: Mon, 14 Aug 2017 14:48:06 +0200 Subject: [PATCH 1/2] Allow for numeric escape sequences Lua strings accept numerical escapes as a "\ddd" sequence, where ddd is 1-3 decimal digits (see Lua Manual, "Lexical Conventions"). This patch makes the parser tolerate escape sequences starting with a digit, copying them to the output as-is. Note that they're not validated in this case. --- minify.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/minify.lua b/minify.lua index 41d7a60..b4db2e1 100644 --- a/minify.lua +++ b/minify.lua @@ -324,9 +324,11 @@ function CreateLuaTokenStream(text) local c2 = get() if c2 == '\\' then local c3 = get() - local esc = CharacterForEscape[c3] - if not esc then - error("Invalid Escape Sequence `"..c3.."`.") + if not c3:match("%d") then + local esc = CharacterForEscape[c3] + if not esc then + error("Invalid Escape Sequence `"..c3.."`.") + end end elseif c2 == c1 then break From 39f0e01aeb54f6a0c050adbeda7f42b245eab0ea Mon Sep 17 00:00:00 2001 From: NiteHawk Date: Thu, 12 Apr 2018 16:40:58 +0200 Subject: [PATCH 2/2] [Fixup] Escape sequence character test "esc" isn't reused, so there is no need for a local variable. The second test thus essentially is if not CharacterForEscape[c3] then ... And we also don't need to string.match() for digits on c3 when we have the Digits[c3] table lookup readily available. --- minify.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/minify.lua b/minify.lua index b4db2e1..972d66f 100644 --- a/minify.lua +++ b/minify.lua @@ -324,11 +324,8 @@ function CreateLuaTokenStream(text) local c2 = get() if c2 == '\\' then local c3 = get() - if not c3:match("%d") then - local esc = CharacterForEscape[c3] - if not esc then - error("Invalid Escape Sequence `"..c3.."`.") - end + if not(Digits[c3] or CharacterForEscape[c3]) then + error("Invalid Escape Sequence `"..c3.."`.") end elseif c2 == c1 then break