зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1819350 - [devtools] Simplify prettyFast sanitize function. r=devtools-reviewers,jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D171242
This commit is contained in:
Родитель
481a7720b5
Коммит
b3e99300e3
|
@ -2507,7 +2507,7 @@
|
|||
"byName": {},
|
||||
"byBlocks": {},
|
||||
"usedIds": {
|
||||
"0": 0
|
||||
"1": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2528,7 +2528,7 @@
|
|||
"byName": {},
|
||||
"byBlocks": {},
|
||||
"usedIds": {
|
||||
"0": 0
|
||||
"1": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6212,44 +6212,45 @@ function prependWhiteSpace(token, lastToken, addedNewline, addedSpace, write, op
|
|||
spaceAdded = true;
|
||||
}
|
||||
}
|
||||
|
||||
const escapeCharacters = {
|
||||
// Backslash
|
||||
"\\": "\\\\",
|
||||
// Newlines
|
||||
"\n": "\\n",
|
||||
// Carriage return
|
||||
"\r": "\\r",
|
||||
// Tab
|
||||
"\t": "\\t",
|
||||
// Vertical tab
|
||||
"\v": "\\v",
|
||||
// Form feed
|
||||
"\f": "\\f",
|
||||
// Null character
|
||||
"\0": "\\x00",
|
||||
// Line separator
|
||||
"\u2028": "\\u2028",
|
||||
// Paragraph separator
|
||||
"\u2029": "\\u2029",
|
||||
// Single quotes
|
||||
"'": "\\'"
|
||||
}; // eslint-disable-next-line prefer-template
|
||||
|
||||
const regExpString = "(" + Object.values(escapeCharacters).join("|") + ")";
|
||||
const escapeCharactersRegExp = new RegExp(regExpString, "g");
|
||||
|
||||
function sanitizerReplaceFunc(_, c) {
|
||||
return escapeCharacters[c];
|
||||
}
|
||||
/**
|
||||
* Make sure that we output the escaped character combination inside string
|
||||
* literals instead of various problematic characters.
|
||||
*/
|
||||
|
||||
|
||||
const sanitize = function () {
|
||||
const escapeCharacters = {
|
||||
// Backslash
|
||||
"\\": "\\\\",
|
||||
// Newlines
|
||||
"\n": "\\n",
|
||||
// Carriage return
|
||||
"\r": "\\r",
|
||||
// Tab
|
||||
"\t": "\\t",
|
||||
// Vertical tab
|
||||
"\v": "\\v",
|
||||
// Form feed
|
||||
"\f": "\\f",
|
||||
// Null character
|
||||
"\0": "\\x00",
|
||||
// Line separator
|
||||
"\u2028": "\\u2028",
|
||||
// Paragraph separator
|
||||
"\u2029": "\\u2029",
|
||||
// Single quotes
|
||||
"'": "\\'"
|
||||
}; // eslint-disable-next-line prefer-template
|
||||
|
||||
const regExpString = "(" + Object.values(escapeCharacters).join("|") + ")";
|
||||
const escapeCharactersRegExp = new RegExp(regExpString, "g");
|
||||
return function (str) {
|
||||
return str.replace(escapeCharactersRegExp, function (_, c) {
|
||||
return escapeCharacters[c];
|
||||
});
|
||||
};
|
||||
}();
|
||||
function sanitize(str) {
|
||||
return str.replace(escapeCharactersRegExp, sanitizerReplaceFunc);
|
||||
}
|
||||
/**
|
||||
* Add the given token to the pretty printed results.
|
||||
*
|
||||
|
|
|
@ -537,44 +537,45 @@ function prependWhiteSpace(
|
|||
}
|
||||
}
|
||||
|
||||
const escapeCharacters = {
|
||||
// Backslash
|
||||
"\\": "\\\\",
|
||||
// Newlines
|
||||
"\n": "\\n",
|
||||
// Carriage return
|
||||
"\r": "\\r",
|
||||
// Tab
|
||||
"\t": "\\t",
|
||||
// Vertical tab
|
||||
"\v": "\\v",
|
||||
// Form feed
|
||||
"\f": "\\f",
|
||||
// Null character
|
||||
"\0": "\\x00",
|
||||
// Line separator
|
||||
"\u2028": "\\u2028",
|
||||
// Paragraph separator
|
||||
"\u2029": "\\u2029",
|
||||
// Single quotes
|
||||
"'": "\\'",
|
||||
};
|
||||
|
||||
// eslint-disable-next-line prefer-template
|
||||
const regExpString = "(" + Object.values(escapeCharacters).join("|") + ")";
|
||||
const escapeCharactersRegExp = new RegExp(regExpString, "g");
|
||||
|
||||
function sanitizerReplaceFunc(_, c) {
|
||||
return escapeCharacters[c];
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that we output the escaped character combination inside string
|
||||
* literals instead of various problematic characters.
|
||||
*/
|
||||
const sanitize = (function() {
|
||||
const escapeCharacters = {
|
||||
// Backslash
|
||||
"\\": "\\\\",
|
||||
// Newlines
|
||||
"\n": "\\n",
|
||||
// Carriage return
|
||||
"\r": "\\r",
|
||||
// Tab
|
||||
"\t": "\\t",
|
||||
// Vertical tab
|
||||
"\v": "\\v",
|
||||
// Form feed
|
||||
"\f": "\\f",
|
||||
// Null character
|
||||
"\0": "\\x00",
|
||||
// Line separator
|
||||
"\u2028": "\\u2028",
|
||||
// Paragraph separator
|
||||
"\u2029": "\\u2029",
|
||||
// Single quotes
|
||||
"'": "\\'",
|
||||
};
|
||||
function sanitize(str) {
|
||||
return str.replace(escapeCharactersRegExp, sanitizerReplaceFunc);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line prefer-template
|
||||
const regExpString = "(" + Object.values(escapeCharacters).join("|") + ")";
|
||||
const escapeCharactersRegExp = new RegExp(regExpString, "g");
|
||||
|
||||
return function(str) {
|
||||
return str.replace(escapeCharactersRegExp, function(_, c) {
|
||||
return escapeCharacters[c];
|
||||
});
|
||||
};
|
||||
})();
|
||||
/**
|
||||
* Add the given token to the pretty printed results.
|
||||
*
|
||||
|
|
Загрузка…
Ссылка в новой задаче