ndless-nspire / Luna

Create TNS files from Lua and XML
Other
61 stars 14 forks source link

Lua scripts containing the string "]]>" result in malformed TNS #26

Closed Legimet closed 1 week ago

Legimet commented 3 months ago

Luna produces a malformed TNS when run on a Lua script containing "]]>" such as the following:

function on.paint(gc)
    gc:drawString("]]>", 5, 20)
end

This is because according to the XML spec,

The right angle bracket (>) may be represented using the string " > ", and MUST, for compatibility, be escaped using either " > " or a character reference when it appears in the string " ]]> " in content, when that string is not marking the end of a CDATA section.

Alternatively, we could place the Lua script in a CDATA section (I believe this is what the TI software does), not escape any characters, and replace all instances of ]]> with ]]]]><![CDATA[>. I personally prefer this solution but could make a PR to implement either.

Vogtinator commented 3 months ago

There's already code to convert & and < to &amp; and &lt; resp., so converting > to &gt; is probably the easiest option.

Legimet commented 3 months ago

I was able to do it using CDATA, and simplify the code a bit in the process. Will submit a PR shortly.

Also, stay tuned for a few more bug reports.