url containing closing parenthesis are parsed incorrectly #23773
Labels
area: @angular-devkit/build-angular
devkit/build-angular:browser
freq1: low
Only reported by a handful of users who observe it rarely
severity5: regression
type: bug/fix
🐞 Bug report
Command (mark with an
x
)Is this a regression?
Yes, the previous version in which this bug was not present was: @angular-devkit/build-angular 14.1.1Description
When loading a CSS file containing a
url
that contains a closing parenthesis)
the regular expression fails to capture the full value in theurl
. In addition if the value contains anotherurl
expression (inside the svg markup) then the parser will try to resolve that url as well.🔬 Minimal Reproduction
npm install
ng build
(orng build --verbose
to see a trace of the error)🔥 Exception or Error
🌍 Your Environment
Anything else relevant?
This is a regression caused by #23691
The current regular expression is
/url(?:\(\s*['"]?)(.*?)(?:['"]?\s*\))/g
which is problematic because it can find a closing parenthesis without finding a closing quote, since the closing quote is optional.A regular expression that solves the problem and still fixes #23680 is something like
/url(?:\(\s*(['"]?))(.*?)(?:\1\s*\))/
. This uses a back reference to ensure that the quotes are the same. This does mean there is an extra capturing group and soconst originalUrl = match[1];
would need to beconst originalUrl = match[2];
instead.A small-ish test case:
The text was updated successfully, but these errors were encountered: