diff --git a/src/runtime/getUrl.js b/src/runtime/getUrl.js index 6c70a337..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(/\n/g, "\\n")}"`; + return `"${url.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`; } return url; diff --git a/test/runtime/__snapshots__/getUrl.test.js.snap b/test/runtime/__snapshots__/getUrl.test.js.snap index a4eda700..f25225d7 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`] = `"https://www.example.com?path=path\\to\\resource"`; diff --git a/test/runtime/getUrl.test.js b/test/runtime/getUrl.test.js index 9dd2ae2b..9d68e475 100644 --- a/test/runtime/getUrl.test.js +++ b/test/runtime/getUrl.test.js @@ -127,5 +127,8 @@ describe("escape", () => { { hash: "#hash", needQuotes: true }, ), ).toMatchSnapshot(); + expect( + getUrl("https://www.example.com?path=path\\to\\resource"), + ).toMatchSnapshot(); }); });