Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML Serialization #36

Merged
merged 11 commits into from
Aug 16, 2017
Merged

XML Serialization #36

merged 11 commits into from
Aug 16, 2017

Conversation

bwrrp
Copy link
Owner

@bwrrp bwrrp commented Aug 15, 2017

This implements the XMLSerializer interface and innerHTML / outerHTML getters from the W3C DOM parsing spec. The corresponding setters will hopefully be added once we get a parser implemented in a future release.

Note that the spec contains a few errors that this implementation has to work around:

This also adds a slimdom.serializeToWellFormedString export, as there would otherwise be no easy way to run the serialization algorithm with the require well-formed flag set.

@bwrrp bwrrp requested a review from DrRataplan August 15, 2017 13:01
});

it('can serialize a CDATASection', () => {
chai.assert.equal(serializer.serializeToString(document.createCDATASection('test')), '<![CDATA[test]]>');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CDataSections are special w.r.t serialization, though they are lightly used in our main dependant (FontoXML), it would be nice to add some tests for createCDATASection(']]'), createCDATASection('&NOT_AN_ENTITY;'), createCDATASection('<element><!-- xml syntax in CData --></element>'), etc?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. It is unfortunately possible (through manipulating data after creation) to create a CDataSection containing ]]>, which will result in invalid XML when serialized. The closest mention of this I could find is a work-around proposed in https://www.w3.org/Bugs/Public/show_bug.cgi?id=16682. The current behavior matches Chrome, Firefox, Edge and Safari, so I guess we should keep it for now and be careful when we mutate CDataSection data.

});

it("throws if given something that isn't a node", () => {
chai.assert.throws(() => (slimdom as any).serializeToWellFormedString({ nodeType: 1 }), TypeError);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use a cast here?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a convenient way to disable type checking for the function call, otherwise TypeScript wouldn't let me pass the object as a Node.

bwrrp added 5 commits August 15, 2017 16:26
The babili minifier has been renamed, and future versions will use the
babel-minify name. This includes related packages, such as the rollup
plugin we use.

Fixes #37
@bwrrp bwrrp merged commit 8e362cc into master Aug 16, 2017
@bwrrp bwrrp deleted the serialization branch August 16, 2017 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants