From 0d0e829cb9d9d53c6b7fa485be576be4a1372a2f Mon Sep 17 00:00:00 2001
From: ruchira-net <ruchira.nu@gmail.com>
Date: Fri, 22 Nov 2024 16:09:38 +1300
Subject: [PATCH 1/4] #1621 fix: correct escaping of backslashes in URL
 wrapping

---
 src/runtime/getUrl.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/runtime/getUrl.js b/src/runtime/getUrl.js
index 6c70a337..a28491fe 100644
--- a/src/runtime/getUrl.js
+++ b/src/runtime/getUrl.js
@@ -21,7 +21,7 @@ module.exports = (url, options) => {
   // Should url be wrapped?
   // See https://drafts.csswg.org/css-values-3/#urls
   if (/["'() \t\n]|(%20)/.test(url) || options.needQuotes) {
-    return `"${url.replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`;
+    return `"${url.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, "\\n')}"`;
   }
 
   return url;

From 65245c93c25973feb11e55b0119213620af95c28 Mon Sep 17 00:00:00 2001
From: ruchira-net <ruchira.nu@gmail.com>
Date: Wed, 27 Nov 2024 09:35:57 +1300
Subject: [PATCH 2/4] #1621 fix: complication error

---
 src/runtime/getUrl.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/runtime/getUrl.js b/src/runtime/getUrl.js
index a28491fe..a7c0bdc8 100644
--- a/src/runtime/getUrl.js
+++ b/src/runtime/getUrl.js
@@ -21,7 +21,7 @@ module.exports = (url, options) => {
   // Should url be wrapped?
   // See https://drafts.csswg.org/css-values-3/#urls
   if (/["'() \t\n]|(%20)/.test(url) || options.needQuotes) {
-    return `"${url.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, "\\n')}"`;
+    return `"${url.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`;
   }
 
   return url;

From e027815f01d479ee376b408282cbaaf96c22bd49 Mon Sep 17 00:00:00 2001
From: ruchira-net <ruchira.nu@gmail.com>
Date: Wed, 27 Nov 2024 11:30:38 +1300
Subject: [PATCH 3/4] test: add snapshot and test case for URL escaping with
 backslashes (#1621)

---
 test/runtime/__snapshots__/getUrl.test.js.snap | 2 ++
 test/runtime/getUrl.test.js                    | 1 +
 2 files changed, 3 insertions(+)

diff --git a/test/runtime/__snapshots__/getUrl.test.js.snap b/test/runtime/__snapshots__/getUrl.test.js.snap
index a4eda700..68a3c6dd 100644
--- a/test/runtime/__snapshots__/getUrl.test.js.snap
+++ b/test/runtime/__snapshots__/getUrl.test.js.snap
@@ -85,3 +85,5 @@ exports[`escape should escape url 41`] = `""image other.png#hash""`;
 exports[`escape should escape url 42`] = `""image other.png#hash""`;
 
 exports[`escape should escape url 43`] = `""image other.png#hash""`;
+
+exports[`escape should escape url 44`] = `"http://url/path\\/"`;
diff --git a/test/runtime/getUrl.test.js b/test/runtime/getUrl.test.js
index 9dd2ae2b..ceb5b58e 100644
--- a/test/runtime/getUrl.test.js
+++ b/test/runtime/getUrl.test.js
@@ -127,5 +127,6 @@ describe("escape", () => {
         { hash: "#hash", needQuotes: true },
       ),
     ).toMatchSnapshot();
+    expect(getUrl("http://url/path\\/")).toMatchSnapshot();
   });
 });

From 28ca565fdc8680f706bf9fcd1ee1f3fff3407d7f Mon Sep 17 00:00:00 2001
From: ruchira-net <ruchira.nu@gmail.com>
Date: Tue, 3 Dec 2024 11:26:03 +1300
Subject: [PATCH 4/4] test: update URL snapshot and test case for escaping
 backslashes (#1621)

---
 test/runtime/__snapshots__/getUrl.test.js.snap | 2 +-
 test/runtime/getUrl.test.js                    | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/test/runtime/__snapshots__/getUrl.test.js.snap b/test/runtime/__snapshots__/getUrl.test.js.snap
index 68a3c6dd..f25225d7 100644
--- a/test/runtime/__snapshots__/getUrl.test.js.snap
+++ b/test/runtime/__snapshots__/getUrl.test.js.snap
@@ -86,4 +86,4 @@ exports[`escape should escape url 42`] = `""image other.png#hash""`;
 
 exports[`escape should escape url 43`] = `""image other.png#hash""`;
 
-exports[`escape should escape url 44`] = `"http://url/path\\/"`;
+exports[`escape should escape url 44`] = `"https://www.example.com?path=path\\to\\resource"`;
diff --git a/test/runtime/getUrl.test.js b/test/runtime/getUrl.test.js
index ceb5b58e..9d68e475 100644
--- a/test/runtime/getUrl.test.js
+++ b/test/runtime/getUrl.test.js
@@ -127,6 +127,8 @@ describe("escape", () => {
         { hash: "#hash", needQuotes: true },
       ),
     ).toMatchSnapshot();
-    expect(getUrl("http://url/path\\/")).toMatchSnapshot();
+    expect(
+      getUrl("https://www.example.com?path=path\\to\\resource"),
+    ).toMatchSnapshot();
   });
 });