Yesterday, I fixed a problem with skin import/export when CDATA sections were involved. A CDATA section is a way to include just about any "character data" in an XML file, without having to worry about the well-formedness of the XML. It's used like this: <![CDATA[...contents...]]>
Since the only way a parser can tell if such a section is finished, nested CDATA sections are a big no-no. The sequence ]]> can not occur inside a CDATA section.
Nucleus exports its skins/templates as such a section (it's the safest way, since we don't know if its valid XML), so problems arise when the skin/template itself is using a CDATA section. The skinbackup.xml file is no longer well-formed. Although only RSS/Atom/... skins are affected, and import still worked fine, the problem had to be taken care of.
The solution
The solution is to replace any occurrence of ]]> in the skin by ]]]]><![CDATA[>, so that when including the contents in a CDATA section, that section will be split into two valid sections.
So, why didn't import fail with the broken files?
Ah, there's trickery involved!
In the import/export code included in Nucleus v2.0/v3.0, some code is present that transforms the read file before parsing the XML. It changes ]]> by }}> (only for nested CDATA). Once the skin data is read, the inverse transformation is done. I can't remember where that code came from. I probably copy-pasted it from somewhere, since the regex used was a rather complicated one.
Can I still import broken skinbackup.xml files?
Yup. The old trickery has been removed and replaced by some new trickery: when invalid CDATA-nesting is found, it is transformed into proper nesting, before the XML is parsed.
Can new exports be imported using old Nucleus versions?
At first, I was afraid this would be a problem. But since the new exports don't have nested CDATA sections, all is fine.
Why all that work? Import/Export did work, didn't it?
From a users perspective: it did. From a developers perspective, it didn't. It wrote out a skinbackup.xml which was claimed to be an XML file, but in fact might be not.

Comments
Add Comment