1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-08 07:45:47 +01:00

Fix util.makeDTD.

Accidentally reverted in the appropriately threatening commit 7ee5792
This commit is contained in:
Doug Kearns
2015-06-09 00:15:41 +10:00
parent 51fffeb2d6
commit b541195188

View File

@@ -972,14 +972,24 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
* for *obj*.
*/
makeDTD: function makeDTD(obj) {
let map = { "'": "&apos;", '"': "&quot;", "%": "&#x25;", "&": "&amp;", "<": "&lt;", ">": "&gt;" };
let map = {
"'": "&apos;", '"': "&quot;", "%": "&#x25;",
"&": "&amp;", "<": "&lt;", ">": "&gt;"
};
return iter(obj)
.map(([k, v]) => ["<!ENTITY ", k, " '", String.replace(v == null ? "null" : typeof v == "xml" ? v.toXMLString() : v,
typeof v == "xml" ? /['%]/g : /['"%&<>]/g,
m => map[m]),
"'>"].join(""))
.join("\n");
function escape(val) {
let isDOM = DOM.isJSONXML(val);
return String.replace(val == null ? "null" :
isDOM ? DOM.toXML(val)
: val,
isDOM ? /['%]/g
: /['"%&<>]/g,
m => map[m]);
}
return iter(obj).map(([k, v]) =>
["<!ENTITY ", k, " '", escape(v), "'>"].join(""))
.join("\n");
},
/**