Skip to content

Commit

Permalink
bugfix: don't crash with two newlines followed by one character betwe…
Browse files Browse the repository at this point in the history
…en two code blocks
  • Loading branch information
FSMaxB committed Mar 11, 2016
1 parent 7cc102b commit 7d154ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion liluat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ function liluat.compile(template, options, template_name, start_path)
end
elseif chunk.text:find("^\n") then --have to trim a newline
if chunk.text:find("^\n.*\n") then --at least two newlines
chunk.text = chunk.text:match("^\n(.*\n)%s-$")
chunk.text = chunk.text:match("^\n(.*\n)%s-$") or chunk.text:match("^\n(.*)$")
elseif chunk.text:find("^\n%s-$") then
chunk.text = ""
else
Expand Down
16 changes: 16 additions & 0 deletions spec/liluat_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,22 @@ another line]]
end)

describe("liluat.compile", function ()
it("should not crash with two newlines and at least one character between two code blocks", function()
local template = liluat.compile([[
{{}}
x{{}}
]])
end)

it("should not crash with tabs at the front either", function()
local template = liluat.compile([[
{{}}
x{{}}
]])
end)

it("should compile templates into code", function ()
local template = "a{{i = 0}}{{= i}}b"
local expected_output = {
Expand Down

0 comments on commit 7d154ac

Please sign in to comment.