mirror of https://github.com/aredn/aredn.git
Improve description and note escaping (#1497)
This commit is contained in:
parent
36bddd2619
commit
5cad7ac101
|
@ -72,10 +72,10 @@ if (request.env.REQUEST_METHOD === "PUT") {
|
|||
}
|
||||
configuration.prepareChanges();
|
||||
if ("description_node" in request.args) {
|
||||
configuration.setSetting("description_node", replace(request.args.description_node || "", "'", "’"));
|
||||
configuration.setSetting("description_node", configuration.escapeString(trim(request.args.description_node)));
|
||||
}
|
||||
if ("notes" in request.args) {
|
||||
uciMesh.set("aredn", "@notes[0]", "private", replace(request.args.notes || "", "'", "’"));
|
||||
uciMesh.set("aredn", "@notes[0]", "private", configuration.escapeString(trim(request.args.notes)));
|
||||
uciMesh.commit("aredn");
|
||||
}
|
||||
if ("node_name" in request.args) {
|
||||
|
|
|
@ -402,3 +402,27 @@ export function countChanges()
|
|||
}
|
||||
return count;
|
||||
};
|
||||
|
||||
const specialCharacters = [
|
||||
[ "&", "&" ], // Must be first
|
||||
[ '"', """ ],
|
||||
[ "'", "'" ],
|
||||
[ "<", "<" ],
|
||||
[ ">", ">" ]
|
||||
];
|
||||
|
||||
export function escapeString(s)
|
||||
{
|
||||
for (let i = 0; i < length(specialCharacters); i++) {
|
||||
s = replace(s, specialCharacters[i][0], specialCharacters[i][1]);
|
||||
}
|
||||
return s;
|
||||
};
|
||||
|
||||
export function unescapeString(s)
|
||||
{
|
||||
for (let i = length(specialCharacters) - 1; i >= 0; i--) {
|
||||
s = replace(s, specialCharacters[i][1], specialCharacters[i][0]);
|
||||
}
|
||||
return s;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue