Bug 1974973 - [devtools] Stop escaping for other platforms when selecting Copy as curl (POSIX) r=devtools-reviewers,ochameau a=RyanVM
- This patch should revert the fixes from Bug 1960198, Bug 1949994 and Bug 1962301.
- The goal of this patch is Copy as curl (POSIX) should only work on Linux.
Differential Revision: https://phabricator.services.mozilla.com/D255784
This commit is contained in:
committed by
rvandermeulen@mozilla.com
parent
7d396ff5b4
commit
0497f73908
@@ -269,7 +269,14 @@ function testEscapeStringPosix() {
|
|||||||
const escapeChar = "'!ls:q:gs|ls|;ping 8.8.8.8;|";
|
const escapeChar = "'!ls:q:gs|ls|;ping 8.8.8.8;|";
|
||||||
is(
|
is(
|
||||||
CurlUtils.escapeStringPosix(escapeChar),
|
CurlUtils.escapeStringPosix(escapeChar),
|
||||||
"$'\\'\\041ls:q:gs^|ls^|;ping 8.8.8.8;^|'",
|
"$'\\'\\041ls:q:gs|ls|;ping 8.8.8.8;|'",
|
||||||
|
"'!' should be escaped."
|
||||||
|
);
|
||||||
|
|
||||||
|
const escapeBangOnlyChar = "!";
|
||||||
|
is(
|
||||||
|
CurlUtils.escapeStringPosix(escapeBangOnlyChar),
|
||||||
|
"$'\\041'",
|
||||||
"'!' should be escaped."
|
"'!' should be escaped."
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -295,21 +302,6 @@ function testEscapeStringPosix() {
|
|||||||
"$'\\xc3\\xa6 \\xc3\\xb8 \\xc3\\xbc \\xc3\\x9f \\xc3\\xb6 \\xc3\\xa9'",
|
"$'\\xc3\\xa6 \\xc3\\xb8 \\xc3\\xbc \\xc3\\x9f \\xc3\\xb6 \\xc3\\xa9'",
|
||||||
"Character codes outside of the decimal range 32 - 126 should be escaped."
|
"Character codes outside of the decimal range 32 - 126 should be escaped."
|
||||||
);
|
);
|
||||||
|
|
||||||
// Assert that ampersands are correctly escaped in case its tried to run on Windows
|
|
||||||
const evilCommand = `query=evil\n\ncmd & calc.exe\n\n`;
|
|
||||||
is(
|
|
||||||
CurlUtils.escapeStringPosix(evilCommand),
|
|
||||||
"$'query=evil\\n\\ncmd ^& calc.exe\\n\\n'",
|
|
||||||
"The evil command is escaped properly"
|
|
||||||
);
|
|
||||||
|
|
||||||
const str = "EvilHeader: &calc.exe&";
|
|
||||||
is(
|
|
||||||
CurlUtils.escapeStringPosix(str),
|
|
||||||
"'EvilHeader: ^&calc.exe^&'",
|
|
||||||
"The evil command is escaped properly"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testEscapeStringWin() {
|
function testEscapeStringWin() {
|
||||||
|
|||||||
@@ -421,10 +421,9 @@ const CurlUtils = {
|
|||||||
return "\\u" + ("0000" + code).substr(code.length, 4);
|
return "\\u" + ("0000" + code).substr(code.length, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escape & and |, which are special characters on Windows.
|
// Escape characters which are not within the charater range
|
||||||
const winSpecialCharsRegEx = /([&\|])/g;
|
// SPACE to "~"(char codes 32 - 126), the `!` (code 33) and '(code 39);
|
||||||
|
if (/[^\x20-\x7E]|!|\'/.test(str)) {
|
||||||
if (/[^\x20-\x7E]|\'/.test(str)) {
|
|
||||||
// Use ANSI-C quoting syntax.
|
// Use ANSI-C quoting syntax.
|
||||||
return (
|
return (
|
||||||
"$'" +
|
"$'" +
|
||||||
@@ -434,14 +433,13 @@ const CurlUtils = {
|
|||||||
.replace(/\n/g, "\\n")
|
.replace(/\n/g, "\\n")
|
||||||
.replace(/\r/g, "\\r")
|
.replace(/\r/g, "\\r")
|
||||||
.replace(/!/g, "\\041")
|
.replace(/!/g, "\\041")
|
||||||
.replace(winSpecialCharsRegEx, "^$1")
|
|
||||||
.replace(/[^\x20-\x7E]/g, escapeCharacter) +
|
.replace(/[^\x20-\x7E]/g, escapeCharacter) +
|
||||||
"'"
|
"'"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use single quote syntax.
|
// Use single quote syntax.
|
||||||
return "'" + str.replace(winSpecialCharsRegEx, "^$1") + "'";
|
return "'" + str + "'";
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user