From a7b60adc0f67d09c23c70e8d7e5d5bb6961fd435 Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 6 Jul 2026 00:42:59 -0400 Subject: [PATCH] fix: parse unquoted `url()` values containing semicolons - Extend `VALUE_REGEX` to match `url(...)` as a single token - Handle unquoted data URIs like `url(data:image/png; base64,...)` - Add test case for unquoted data URI with semicolon in `url()` --- index.js | 3 ++- test/data.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 7e9c3ec..d17e8fb 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,8 @@ var WHITESPACE_REGEX = /^\s*/; // declaration var PROPERTY_REGEX = /^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/; var COLON_REGEX = /^:\s*/; -var VALUE_REGEX = /^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|[^};])+)/; +var VALUE_REGEX = + /^((?:'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|url\((?:'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|[^)]*)\)|[^};])+)/; var SEMICOLON_REGEX = /^[;\s]*/; // https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill diff --git a/test/data.js b/test/data.js index 396b99d..415700b 100644 --- a/test/data.js +++ b/test/data.js @@ -35,6 +35,7 @@ const cases = [ "background-image: url('http://example.com/img.png')", 'background: url(http://example.com/img.png) no-repeat', 'background: url("data:image/svg+xml,")', + 'background: url(data:image/png; base64,abc+/=)', // vendor prefixes 'background: -webkit-linear-gradient(90deg, black, #111)',