XML throws parsing exception after it removes all whitespace between attributes if CRLF (\r\n) appears
- Dominant language
- ActionScript
- Stars
- 380
- Forks
- 120
- PR merge metrics
- No merged PRs in 30d
Description
For XML text like this (i.e. e4x raw data during an HTTPService):
The XML object will remove "\r\n " or " \r\n", causing the attributes to be squished together, throwing a parsing error.
The problem is trimXMLWhitespace():
` static private function trimXMLWhitespace(value:String):String
{
return value.replace(/^\s+|\s+$/gm,'');
}
`
The "^" and "$" are matching up with the literal newlines (\r\n). Perhaps the original intent was to match just the beginning / end of the entire string.
A quick workaround is to either return just "value" or replace with a single space instead of blank:
` static private function trimXMLWhitespace(value:String):String
{
return value.replace(/^\s+|\s+$/gm,' ');
}
`
I would imagine that CRLF embedded in actual text values are also getting stripped out unintentionally, but haven't tested that.
Test case:
[TestXML.mxml.txt](https://github.com/apache/royale-asjs/files/5579860/TestXML.mxml.txt)
Test exception:
Uncaught Error: XML Parsing Error: not well-formed
Location: file:///C:/src/royale-test-xml/bin/js-debug/index.html
Line Number 1, Column 39:<parseRoot><myxml><mynode red="value1"green="value2" blue="value3"yellow="value4" /></myxml></parseRoot>
--------------------------------------^
Contributor guide
No contributing guide indexed for this repository
Research direction
Locate trimXMLWhitespace() and reproduce the failure with the linked TestXML.mxml.txt case, paying attention to CRLF between XML attributes. Check the resulting parser error and verify that the completed change preserves valid separation between attributes without stripping embedded text whitespace.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- xml
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100