mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
refactor(ext) Decrease of StringPrototypeReplace recurrent usage (#15058)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
132c761e87
commit
213d831ae3
2 changed files with 24 additions and 32 deletions
|
@ -720,27 +720,20 @@
|
||||||
|
|
||||||
// Replace escape sequences that can modify output.
|
// Replace escape sequences that can modify output.
|
||||||
function replaceEscapeSequences(string) {
|
function replaceEscapeSequences(string) {
|
||||||
|
const escapeMap = {
|
||||||
|
"\b": "\\b",
|
||||||
|
"\f": "\\f",
|
||||||
|
"\n": "\\n",
|
||||||
|
"\r": "\\r",
|
||||||
|
"\t": "\\t",
|
||||||
|
"\v": "\\v",
|
||||||
|
};
|
||||||
|
|
||||||
return StringPrototypeReplace(
|
return StringPrototypeReplace(
|
||||||
StringPrototypeReplace(
|
StringPrototypeReplace(
|
||||||
StringPrototypeReplace(
|
string,
|
||||||
StringPrototypeReplace(
|
/([\b\f\n\r\t\v])/g,
|
||||||
StringPrototypeReplace(
|
(c) => escapeMap[c],
|
||||||
StringPrototypeReplace(
|
|
||||||
StringPrototypeReplace(string, /[\b]/g, "\\b"),
|
|
||||||
/\f/g,
|
|
||||||
"\\f",
|
|
||||||
),
|
|
||||||
/\n/g,
|
|
||||||
"\\n",
|
|
||||||
),
|
|
||||||
/\r/g,
|
|
||||||
"\\r",
|
|
||||||
),
|
|
||||||
/\t/g,
|
|
||||||
"\\t",
|
|
||||||
),
|
|
||||||
/\v/g,
|
|
||||||
"\\v",
|
|
||||||
),
|
),
|
||||||
// deno-lint-ignore no-control-regex
|
// deno-lint-ignore no-control-regex
|
||||||
/[\x00-\x1f\x7f-\x9f]/g,
|
/[\x00-\x1f\x7f-\x9f]/g,
|
||||||
|
|
|
@ -271,20 +271,19 @@
|
||||||
webidl.configurePrototype(FormData);
|
webidl.configurePrototype(FormData);
|
||||||
const FormDataPrototype = FormData.prototype;
|
const FormDataPrototype = FormData.prototype;
|
||||||
|
|
||||||
const escape = (str, isFilename) =>
|
const escape = (str, isFilename) => {
|
||||||
StringPrototypeReplace(
|
const escapeMap = {
|
||||||
StringPrototypeReplace(
|
"\n": "%0A",
|
||||||
StringPrototypeReplace(
|
"\r": "%0D",
|
||||||
|
'"': "%22",
|
||||||
|
};
|
||||||
|
|
||||||
|
return StringPrototypeReplace(
|
||||||
isFilename ? str : StringPrototypeReplace(str, /\r?\n|\r/g, "\r\n"),
|
isFilename ? str : StringPrototypeReplace(str, /\r?\n|\r/g, "\r\n"),
|
||||||
/\n/g,
|
/([\n\r"])/g,
|
||||||
"%0A",
|
(c) => escapeMap[c],
|
||||||
),
|
|
||||||
/\r/g,
|
|
||||||
"%0D",
|
|
||||||
),
|
|
||||||
/"/g,
|
|
||||||
"%22",
|
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* convert FormData to a Blob synchronous without reading all of the files
|
* convert FormData to a Blob synchronous without reading all of the files
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue