Skip to content

Commit

Permalink
[INTERNAL] Encode property default values as JS string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
codeworrior committed Jan 25, 2021
1 parent 840cab9 commit 7d1b103
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/processors/jsdoc/lib/ui5/template/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -3793,9 +3793,25 @@ function createAPIXML(symbols, filename, options) {
return !!symbol && symbol.kind === "enum";
}

var replacement = {
"\t": "\\t",
"\n": "\\n",
"\r": "\\r",
"\"": "\\\"",
"\\": "\\\\"
};

/**
* Converts the given value into its JavaScript source code format.
*
* Strings will be enclosed in double quotes with special chars being escaped,
* all other values will be used 'literally'.
*/
function toRaw(value, type) {
if ( typeof value === "string" && !isEnum(type) ) {
value = "\"" + value.replace(/"/g, "\\\"") + "\"";
return "\"" + value.replace(/[\u0000-\u001f"\\]/g, function(c) {
return replacement[c] || "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0");
}) + "\"";
}
return value;
}
Expand Down

0 comments on commit 7d1b103

Please sign in to comment.