alek-sys / sublimetext_indentxml

Plugin for Sublime Text editor for reindenting XML and JSON files
MIT License
534 stars 135 forks source link

Fail to indent if the XML contains a CDATA with another XML inside #57

Closed luxifer closed 7 years ago

luxifer commented 10 years ago
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 549, in run_
    return self.run(edit)
  File "indentxml in /Users/florentviel/Library/Application Support/Sublime Text 3/Installed Packages/Indent XML.sublime-package", line 49, in run
  File "indentxml in /Users/florentviel/Library/Application Support/Sublime Text 3/Installed Packages/Indent XML.sublime-package", line 96, in indent
  File "indentxml in /Users/florentviel/Library/Application Support/Sublime Text 3/Installed Packages/Indent XML.sublime-package", line 93, in indent
  File "X/xml/dom/minidom.py", line 1972, in parseString
  File "X/xml/dom/expatbuilder.py", line 926, in parseString
  File "X/xml/dom/expatbuilder.py", line 221, in parseString
xml.parsers.expat.ExpatError: XML or text declaration not at start of entity: line 1, column 645

Sublime version: 3

hello-alf commented 9 years ago

I get this error Traceback (most recent call last): File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 556, in run_ return self.run(edit) File "indentxml in C:\Users\lquispe\AppData\Roaming\Sublime Text 3\Installed Packages\Indent XML.sublime-package", line 49, in run File "indentxml in C:\Users\lquispe\AppData\Roaming\Sublime Text 3\Installed Packages\Indent XML.sublime-package", line 96, in indent File "indentxml in C:\Users\lquispe\AppData\Roaming\Sublime Text 3\Installed Packages\Indent XML.sublime-package", line 93, in indent File "./xml/dom/minidom.py", line 1970, in parseString File "./xml/dom/expatbuilder.py", line 926, in parseString File "./xml/dom/expatbuilder.py", line 221, in parseString xml.parsers.expat.ExpatError: mismatched tag: line 1, column 616

nelreina commented 9 years ago

Also failed to indend a xml with an & inside CDATA.

alek-sys commented 8 years ago

Note that XML in CDATA need to be quoted, so XML need to be valid to be indented. Also it is a good practice to attach sample XML to the issue, it is hard to diagnose issue.

nelreina commented 8 years ago

@alek-sys All characters in CDATA should be allowed. That is the whole purpose of Cdata. But when CDATA contains special characters (like '&' ) this sublime package does not work.

alek-sys commented 8 years ago

@nelreina I was going to point you to the XML spec CDATA section.. and turned out you are quite right, spec clearly says "Within a CDATA section, only the CDEnd string is recognized as markup, so that left angle brackets and ampersands may occur in their literal form; they need not (and cannot) be escaped using "<" and "&".

So ok, this is an issue in xml.minidom - I'll look what can be done here.

dolpsdw commented 8 years ago

I think this still fails. Here you have a sample http://pastebin.com/YWZsVjRA

memboc commented 7 years ago

Still fails with CDATA. Another sample: http://pastebin.com/9BJ1mWpN

Babeetlebum commented 7 years ago

I have the same issue, most of our XMLs use CDATA with HTML inside so the plugin quite rarely works

Also this guy talked about it in the sublimetext forums and gives an easy test case if needed

alek-sys commented 7 years ago

Brace yourself, the fix is coming!

And seriously, all these issues have the same reason which will be fixed next week, I'll release updated version from another branch. It does mindom monkey-patching instead of doing weird CDATA substitutions so everything will finally work.