Typing a certain sequence of characters in XML mode results in a memory leak/infinite loop which eventually crashes the page. To reproduce:
<A><![CDATA[</A>
This bug is present in the current version of Ace, and at least as far back as Ace 1.2.3.
Crashes on Windows 7 and 10, in Chrome.
I've identified the issue as this line: https://github.com/ajaxorg/ace/blob/dbdf8aaad697e2ded8fd69249b72a7e898583afa/lib/ace/mode/xml/sax.js#L479
end
is equal to -1 because the string "]]>" doesn't exist. This causes the return value to be 2, causing an infinite loop. I am relatively unfamiliar with Ace editor. I found a simple solution:
var end = source.indexOf(']]>',start+9);
if (end < 0) {
return -1;
}
A small problem is that the document will stop tokenizing after the broken CDATA[ string so we lose syntax highlighting. It would be nice if we could somehow keep the syntax highlighting.
the sax.js is a third party library that is used for linting, it should not affect syntax highlighting.
Considering the amount of bugs you found in it, i wonder if we should switch to something else, e.g. https://www.npmjs.com/package/xmlchecker or http://syssgx.github.io/xml.js/
Another alternative might be https://github.com/lddubeau/saxes
Looks like it might address a number of the open xml bugs
An issue for me is the current xml mode linting is validating for an xml fragment not a xml document.
E.g.
just some text
and
<foo/><foo/>
are considered valid xml. Is this by design?
I put together a repl page to show saxes
in action
https://repl.it/@apb2006/xml-parser-saxes-test
Just for the record, there is other content that triggers the same memory leak. Go to https://ace.c9.io/build/kitchen-sink.html and switch to XML mode. Somewhere in the middle, type <?p
. After a couple of seconds, the browser crashes. Safari, Chrome, FF - all the same.
Most helpful comment
Just for the record, there is other content that triggers the same memory leak. Go to https://ace.c9.io/build/kitchen-sink.html and switch to XML mode. Somewhere in the middle, type
<?p
. After a couple of seconds, the browser crashes. Safari, Chrome, FF - all the same.