function encodingInfoForChar(c) { var info = encodingInfoMap.get(c); if (info) {
return info;
}
return encodeNone;
}
function encodingForChar(c, type) { var info = encodingInfoForChar(c); if (!info[type]) {
return c;
}
return encodingMap.get(c);
}
const doc = new DOMParser().parseFromString("<root></root>", "text/xml"); const root = doc.documentElement; for (let i = 0; i < 255; ++i) {
let el = doc.createElement("span");
el.setAttribute("x", String.fromCharCode(i));
el.textContent = " ";
root.appendChild(el);
} for (let type of ["xml", "xhtml", "htmlBasic", "html"]) {
let str = encoders[type](doc).encodeToString(); const prefix = '<root><span x="'; const suffix = '"> </span></root>'; Assert.ok(str.startsWith(prefix), `${type} serialization starts correctly`); Assert.ok(str.endsWith(suffix), `${type} serialization ends correctly`);
str = str.substring(prefix.length, str.length - suffix.length);
let encodings = str.split('"> </span><span x="'); for (let i = 0; i < 255; ++i) {
let c = String.fromCharCode(i); Assert.equal(
encodingForChar(c, type),
encodings[i],
`${type} encoding of char ${i} is correct`
);
}
}
// Verify that we don't escape entities in attributes with JS code. const docWithJS = new DOMParser().parseFromString("<root></root>", "text/xml"); const rootWithJS = docWithJS.documentElement; const htmlNS = "http://www.w3.org/1999/xhtml"; const jsCode = "x < 2 || y > 3";
let div = docWithJS.createElementNS(htmlNS, "div");
div.setAttribute("href", `javascript:${jsCode}`);
div.setAttribute("src", `javascript:${jsCode}`);
div.setAttribute("onclick", jsCode);
div.setAttribute("onload", jsCode);
rootWithJS.appendChild(div); for (let type of ["xml", "xhtml", "htmlBasic", "html"]) {
let str = encoders[type](docWithJS).encodeToString(); Assert.equal(
str.search("&[a-z]+;"),
-1,
`${type} encoding does not escape entities in attributes with JS code`
);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.27 Sekunden
(vorverarbeitet am 2026-08-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.