Skip to content

Commit 3e4ea77

Browse files
committedJul 19, 2024·
fix(@angular/build): correctly detect comma in Sass URL lexer
The Sass rebasing lexer was incorrectly checking for a comma in certain cases previously. This has now been corrected and url usage that immediately follows a comma within a rule will now be extracted as expected. (cherry picked from commit 8ff687d)
1 parent 3573ac6 commit 3e4ea77

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed
 

‎packages/angular/build/src/tools/sass/lexer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function* findUrls(
5555
if (pos > 0) {
5656
pos -= 2;
5757
next();
58-
if (!isWhitespace(current) && current !== 0x0027 && current !== 0x003a) {
58+
if (!isWhitespace(current) && current !== 0x002c && current !== 0x003a) {
5959
// Skip - not a url token
6060
pos += 3;
6161
continue;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import { findUrls } from './lexer';
10+
11+
describe('Sass URL lexer', () => {
12+
it('should find url immediately after a colon, comma, or whitespace', () => {
13+
const input = `.c{property:url("first"),url("second"), url("third");}`;
14+
15+
const result = [...findUrls(input)];
16+
17+
expect(result).toEqual([
18+
{ start: 16, end: 23, value: 'first' },
19+
{ start: 29, end: 37, value: 'second' },
20+
{ start: 44, end: 51, value: 'third' },
21+
]);
22+
});
23+
24+
it('should find full url with string containing url function', () => {
25+
const input = `.c{property:url("url('abc')");}`;
26+
27+
const result = [...findUrls(input)];
28+
29+
expect(result).toEqual([{ start: 16, end: 28, value: `url('abc')` }]);
30+
});
31+
});

0 commit comments

Comments
 (0)
Please sign in to comment.