From 96a6012d04665fd2001dd52f6f7f60ed386c2d1c Mon Sep 17 00:00:00 2001 From: Guillaume Date: Mon, 3 May 2021 10:27:09 +0200 Subject: [PATCH] fix: allow spaces surrounding url --- lib/CSSStyleDeclaration.test.js | 6 ++++++ lib/parsers.js | 1 + 2 files changed, 7 insertions(+) diff --git a/lib/CSSStyleDeclaration.test.js b/lib/CSSStyleDeclaration.test.js index 9fa8ed3b..97acbd8c 100644 --- a/lib/CSSStyleDeclaration.test.js +++ b/lib/CSSStyleDeclaration.test.js @@ -384,6 +384,12 @@ describe('CSSStyleDeclaration', () => { expect(style.backgroundImage).toEqual('url(http://some/url/here3.png)'); }); + test('url parsing works surrounded by spaces', () => { + var style = new CSSStyleDeclaration(); + style.backgroundImage = 'url( http://some/url/here1.png )'; + expect(style.backgroundImage).toEqual('url(http://some/url/here1.png)'); + }); + test('setting 0 to a padding or margin works', () => { var style = new CSSStyleDeclaration(); style.padding = 0; diff --git a/lib/parsers.js b/lib/parsers.js index 8ecdf5e3..d01aff04 100644 --- a/lib/parsers.js +++ b/lib/parsers.js @@ -237,6 +237,7 @@ exports.parseUrl = function parseUrl(val) { if (str[0] === '"' || str[0] === "'") { str = str.substr(1, str.length - 2); } + str = str.trim(); var i; for (i = 0; i < str.length; i++) {