Bug 1968414 - [devtools] Escape carriage return character properly r=devtools-reviewers,nchevobbe a=pascalc

Differential Revision: https://phabricator.services.mozilla.com/D254323
This commit is contained in:
Hubert Boma Manilla 2025-07-01 22:59:38 +00:00 committed by pchevrel@mozilla.com
parent 02dcff1b77
commit 4ee9693d9e
2 changed files with 3 additions and 3 deletions

View file

@ -344,7 +344,7 @@ function testEscapeStringWin() {
const newLines = "line1\r\nline2\r\rline3\n\nline4"; const newLines = "line1\r\nline2\r\rline3\n\nline4";
is( is(
CurlUtils.escapeStringWin(newLines), CurlUtils.escapeStringWin(newLines),
'^"line1^\n\nline2\r\rline3^\n\n^\n\nline4^"', '^\"line1^\n\nline2^\n\n^\n\nline3^\n\n^\n\nline4^\"',
"Newlines should be escaped." "Newlines should be escaped."
); );
@ -365,7 +365,7 @@ function testEscapeStringWin() {
const evilCommand = `query=evil\r\rcmd" /c timeout /t 3 & calc.exe\r\r`; const evilCommand = `query=evil\r\rcmd" /c timeout /t 3 & calc.exe\r\r`;
is( is(
CurlUtils.escapeStringWin(evilCommand), CurlUtils.escapeStringWin(evilCommand),
'^"query=evil\r\rcmd\\" /c timeout /t 3 & calc.exe\r\r^"', '^\"query=evil^\n\n^\n\ncmd\\\" /c timeout /t 3 & calc.exe^\n\n^\n\n^\"',
"The evil command is escaped properly" "The evil command is escaped properly"
); );
} }

View file

@ -484,7 +484,7 @@ const CurlUtils = {
// Lastly we replace new lines with ^ and TWO new lines because the first // Lastly we replace new lines with ^ and TWO new lines because the first
// new line is there to enact the escape command the second is the character // new line is there to enact the escape command the second is the character
// to escape (in this case new line). // to escape (in this case new line).
.replace(/\r?\n/g, "^\n\n") + .replace(/\r?\n|\r/g, "^\n\n") +
encapsChars encapsChars
); );
}, },