nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.63k stars 1.47k forks source link

xmltree does not escape newlines but prevents them from being escaped #24062

Open IcedQuinn opened 2 months ago

IcedQuinn commented 2 months ago

Description

toXmlAttributes escapes the incoming string. This is OK but it does not escape whitespace characters like the carriage return or linefeed. Since XML dictates all whitespace (such as a newline) be interpreted as a single blank space during reading—a string cannot be reversibly stored in XML with the xmltree module.

Attempting to escape the XML manually fails because the ampersands are consumed during escaping.

Nim Version

2.0.8

Current Output

No response

Expected Output

No response

Known Workarounds

It may be possible to break the XmlAttributes abstraction and inject the manually escaped string there. I have not tried.

Additional Information

metagn commented 2 months ago

Relevant proc: https://github.com/nim-lang/Nim/blob/7cd17772181a8577a79ee166f4dc96b396dd59d2/lib/pure/xmltree.nim#L740