Skip to content

Commit

Permalink
Fix invalid escape when using special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Mar 9, 2020
1 parent db4ed1f commit a8410a6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions nelua/utils/pegger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ local c_quote_patt_end = "\

local quotes_defs = {
to_special_character_lua = function(s)
return '\\' .. string.byte(s)
return string.format('\\%03d', string.byte(s))
end,
to_special_character_c = function(s)
return string.format('\\x%02x', string.byte(s))
return string.format('\\%03o', string.byte(s))
end
}

Expand Down
4 changes: 2 additions & 2 deletions spec/003-pegger_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ it("c double quoting", function()
assert.same(q "\n", [["\n"]])
assert.same(q "\r", [["\r"]])
assert.same(q "\v", [["\v"]])
assert.same(q "\001", [["\x01"]])
assert.same(q "\255", [["\xff"]])
assert.same(q "\001", [["\001"]])
assert.same(q "\255", [["\377"]])

-- trigraphs
assert.same(q "??=", [["?\?="]])
Expand Down
2 changes: 1 addition & 1 deletion spec/04-luagenerator_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ end)
it("string", function()
assert.generate_lua([[return 'a', "b", [=[c]=] ]], [[return "a", "b", "c"]])
assert.generate_lua([[return "'", '"']])
assert.generate_lua([[return "'\1", '"\1']])
assert.generate_lua([[return "'\001", '"\001']])
end)
it("boolean", function()
assert.generate_lua("return true, false")
Expand Down
2 changes: 1 addition & 1 deletion spec/05-cgenerator_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ end)

it("string", function()
assert.generate_c([[local a = "hello"]], [["hello"]])
assert.generate_c([[local a = "\x01"]], [["\x01"]])
assert.generate_c([[local a = "\001"]], [["\001"]])
end)

it("boolean", function()
Expand Down

0 comments on commit a8410a6

Please sign in to comment.