Crash when creating Richtext with string where macro appears at the end
oniietzschan opened this issue · comments
This code:
local txt
function love.load()
local Richtext = require 'richtext'
txt = Richtext:new({
"Test {somemacro}",
somemacro = {1, 0, 1},
})
end
function love.draw()
txt:draw(10, 10)
end
Will produce the following error:
Error: richtext.lua:85: attempt to index local 'textfragment' (a nil value)
stack traceback:
[string "boot.lua"]:637: in function '__index'
richtext.lua:85: in function 'parsefragment'
richtext.lua:103: in function 'parse'
richtext.lua:40: in function 'new'
main.lua:5: in function 'load'
[string "boot.lua"]:488: in function <[string "boot.lua"]:487>
[C]: in function 'xpcall'
[string "boot.lua"]:650: in function <[string "boot.lua"]:639>
[C]: in function 'xpcall'
I've fixed this by changing the line parsefragment(self.parsedtext, text:match('[^}]+$'))
to parsefragment(self.parsedtext, text:match('[^}]+$') or '')
, but I'll play around with it for a bit longer before submitting a PR.