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

Treat tabs as XML characters, per spec #6

Merged
merged 1 commit into from
Mar 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/serialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const xnv = require("xml-name-validator");
const attributeUtils = require("./attributes");
const { NAMESPACES, VOID_ELEMENTS, NODE_TYPES } = require("./constants");

const XML_CHAR = /^(\x20|\x0D|\x0A|[ -\uD7FF]|[\uE000-\uFFFD]|(?:[\uD800-\uDBFF][\uDC00-\uDFFF]))*$/;
const XML_CHAR = /^(\x09|\x0A|\x0D|[\x20-\uD7FF]|[\uE000-\uFFFD]|(?:[\uD800-\uDBFF][\uDC00-\uDFFF]))*$/;
const PUBID_CHAR = /^(\x20|\x0D|\x0A|[a-zA-Z0-9]|[-'()+,./:=?;!*#@$_%])*$/;

function asciiCaseInsensitiveMatch(a, b) {
Expand Down
21 changes: 20 additions & 1 deletion test/jsdom.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
const { JSDOM } = require("jsdom");

const XMLSerializer = require("../lib/XMLSerializer").interface;
const { produceXMLSerialization } = require("../lib/serialization");

function serialize(node) {
var serializer = new XMLSerializer();
return serializer.serializeToString(node);
}

function wellFormedSerialize(node) {
return produceXMLSerialization(node, true);
}

describe("JSDOM imports", () => {
test("Serializes custom prefixes", function() {
test("Serializes custom prefixes", () => {
const {
window: { document }
} = new JSDOM(
Expand All @@ -26,4 +31,18 @@ describe("JSDOM imports", () => {
`<element xmlns:prefix="https://example.com/" prefix:hasOwnProperty="value"/>`
);
});

test("Serializes tab characters", () => {
const {
window: { document }
} = new JSDOM(
`<dummy />`,
{ contentType: "text/xml" }
);

const el = document.createElement("el");
el.appendChild(document.createTextNode("\t"));

expect(wellFormedSerialize(el)).toEqual("<el>\t</el>");
});
});