diff --git a/cjs/interface/attr.js b/cjs/interface/attr.js index 79c6868..65af5ba 100644 --- a/cjs/interface/attr.js +++ b/cjs/interface/attr.js @@ -46,7 +46,7 @@ class Attr extends Node { if (emptyAttributes.has(name) && !value) { return ignoreCase(this) ? name : `${name}=""`; } - const escapedValue = ignoreCase(this) ? value.replace(QUOTE, '"') : escape(value); + const escapedValue = (ignoreCase(this) ? value : escape(value)).replace(QUOTE, '"'); return `${name}="${escapedValue}"`; } diff --git a/esm/interface/attr.js b/esm/interface/attr.js index f84a07e..6c617f6 100644 --- a/esm/interface/attr.js +++ b/esm/interface/attr.js @@ -45,7 +45,7 @@ export class Attr extends Node { if (emptyAttributes.has(name) && !value) { return ignoreCase(this) ? name : `${name}=""`; } - const escapedValue = ignoreCase(this) ? value.replace(QUOTE, '"') : escape(value); + const escapedValue = (ignoreCase(this) ? value : escape(value)).replace(QUOTE, '"'); return `${name}="${escapedValue}"`; } diff --git a/test/interface/attr.js b/test/interface/attr.js index f7202e6..f441a8a 100644 --- a/test/interface/attr.js +++ b/test/interface/attr.js @@ -1,6 +1,6 @@ const assert = require('../assert.js').for('Attr'); -const {parseHTML} = global[Symbol.for('linkedom')]; +const {parseHTML, DOMParser} = global[Symbol.for('linkedom')]; const {document} = parseHTML(''); @@ -20,3 +20,11 @@ assert(attributes.removeNamedItem('test'), void 0, 'removeNamedItem'); assert(attributes.item(0), null, 'attributes.item()'); assert(attributes.setNamedItem(attr), void 0, 'setNamedItem'); +/** @type {(str: string) => Document} */ +const parseXML = xmlStr => new DOMParser().parseFromString(xmlStr, 'text/xml'); +const xmlDoc = parseXML(''); + +assert(xmlDoc.toString(), ''); +assert(xmlDoc.firstElementChild.toString(), ''); +assert(xmlDoc.firstElementChild.outerHTML, ''); +assert(xmlDoc.firstElementChild.attributes.attr.value, 'a"b"c');