From 5ad78a48db6b50b1b3eb741e5c6db28752b6e22c Mon Sep 17 00:00:00 2001 From: roytam1 Date: Wed, 19 Jan 2022 10:18:44 +0800 Subject: [PATCH] Bug 1737252 - [devtools] Escaping back tick signs. r=nchevobbe, a=RyanVM --- devtools/client/shared/curl.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/devtools/client/shared/curl.js b/devtools/client/shared/curl.js index 54cdc05cbf..f514ae1d74 100644 --- a/devtools/client/shared/curl.js +++ b/devtools/client/shared/curl.js @@ -8,6 +8,7 @@ * Copyright (C) 2008, 2009 Anthony Ricaud * Copyright (C) 2011 Google Inc. All rights reserved. * Copyright (C) 2009 Mozilla Foundation. All rights reserved. + * Copyright (C) 2022 Moonchild Productions. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -400,9 +401,15 @@ const CurlUtils = { */ escapeStringWin: function (str) { /* - Replace dollar sign because of commands (e.g $(cmd.exe)) in - powershell when using double quotes. - Useful details http://www.rlmueller.net/PowerShellEscape.htm + Replace the backtick character ` with `` in order to escape it. + The backtick character is an escape character in PowerShell and + can, among other things, be used to disable the effect of some + of the other escapes created below. + + Replace dollar sign because of commands in powershell when using + double quotes. e.g $(calc.exe). + + Also see http://www.rlmueller.net/PowerShellEscape.htm for details. Replace quote by double quote (but not by \") because it is recognized by both cmd.exe and MS Crt arguments parser. @@ -416,13 +423,15 @@ const CurlUtils = { MS Crt arguments parser won't collapse them. Replace new line outside of quotes since cmd.exe doesn't let - to do it inside. + us do it inside. */ - return "\"" + str.replace(/\$/g, "`$") - .replace(/"/g, "\"\"") - .replace(/%/g, "\"%\"") - .replace(/\\/g, "\\\\") - .replace(/[\r\n]+/g, "\"^$&\"") + "\""; + return "\"" + + str.replaceAll("`", "``") + .replaceAll("$", "`$") + .replaceAll('"', '""') + .replaceAll("%", '"%"') + .replace(/\\/g, "\\\\") + .replace(/[\r\n]+/g, "\"^$&\"") + "\""; } };