Skip to content

Commit

Permalink
Treat tabs as XML characters, per spec
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Mar 17, 2019
1 parent 7cb02a7 commit 1efd9c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
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>");
});
});

0 comments on commit 1efd9c9

Please sign in to comment.