Fixed 267U.pre2
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
const map = {
|
||||
"&": "&",
|
||||
"<": "<",
|
||||
">": ">",
|
||||
'"': """,
|
||||
"'": "'"
|
||||
};
|
||||
const beginingOfCDATA = "<![CDATA[";
|
||||
const endOfCDATA = "]]>";
|
||||
export function escapeValue(x) {
|
||||
let insideOfCDATA = false;
|
||||
let builder = "";
|
||||
for(let i = 0; i < x.length;){
|
||||
if (insideOfCDATA) {
|
||||
if (x.slice(i, i + beginingOfCDATA.length) === beginingOfCDATA) {
|
||||
insideOfCDATA = true;
|
||||
i += beginingOfCDATA.length;
|
||||
} else {
|
||||
builder += x[i++];
|
||||
}
|
||||
} else {
|
||||
if (x.slice(i, i + endOfCDATA.length) === endOfCDATA) {
|
||||
insideOfCDATA = false;
|
||||
i += endOfCDATA.length;
|
||||
} else {
|
||||
const b = x[i++];
|
||||
builder += map[b] || b;
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
export function escapeAttribute(x) {
|
||||
return Object.entries(map).reduce((a, [k, v])=>a.replace(k, v), x);
|
||||
}
|
||||
Reference in New Issue
Block a user