From 4ee9693d9ec7fc1cde10cd58e4d0f020b9a2dda9 Mon Sep 17 00:00:00 2001 From: Hubert Boma Manilla Date: Tue, 1 Jul 2025 22:59:38 +0000 Subject: [PATCH] Bug 1968414 - [devtools] Escape carriage return character properly r=devtools-reviewers,nchevobbe a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D254323 --- devtools/client/netmonitor/test/browser_net_curl-utils.js | 4 ++-- devtools/client/shared/curl.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/devtools/client/netmonitor/test/browser_net_curl-utils.js b/devtools/client/netmonitor/test/browser_net_curl-utils.js index ef98d85b15c9..84a88c8a4d8d 100644 --- a/devtools/client/netmonitor/test/browser_net_curl-utils.js +++ b/devtools/client/netmonitor/test/browser_net_curl-utils.js @@ -344,7 +344,7 @@ function testEscapeStringWin() { const newLines = "line1\r\nline2\r\rline3\n\nline4"; is( 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." ); @@ -365,7 +365,7 @@ function testEscapeStringWin() { const evilCommand = `query=evil\r\rcmd" /c timeout /t 3 & calc.exe\r\r`; is( 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" ); } diff --git a/devtools/client/shared/curl.js b/devtools/client/shared/curl.js index 2d0f142fd44f..0c19c13abb7f 100644 --- a/devtools/client/shared/curl.js +++ b/devtools/client/shared/curl.js @@ -484,7 +484,7 @@ const CurlUtils = { // 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 // to escape (in this case new line). - .replace(/\r?\n/g, "^\n\n") + + .replace(/\r?\n|\r/g, "^\n\n") + encapsChars ); },