Skip to content

Commit

Permalink
add quotes around contents of url()
Browse files Browse the repository at this point in the history
  • Loading branch information
bartveneman committed Sep 3, 2024
1 parent b9638ef commit 3cc7c52
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ export function format(css, { minify = false } = {}) {
buffer += print_operator(node)
} else if (node.type === 'Parentheses') {
buffer += OPEN_PARENTHESES + print_list(node.children) + CLOSE_PARENTHESES
} else if (node.type === 'Url') {
buffer += 'url(' + QUOTE + node.value + QUOTE + CLOSE_PARENTHESES
} else {
buffer += substr(node)
}
Expand Down
2 changes: 1 addition & 1 deletion test/declarations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test('Declarations end with a semicolon (;)', () => {
}
`)
let expected = `@font-face {
src: url('test');
src: url("test");
font-family: Test;
}
Expand Down
24 changes: 24 additions & 0 deletions test/values.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,28 @@ test('does not break space toggles (minified)', () => {
assert.is(actual, expected)
})

test('adds quotes around strings in url()', () => {
let actual = format(`a {
background-image: url("star.gif");
list-style-image: url('../images/bullet.jpg');
content: url("pdficon.jpg");
cursor: url(mycursor.cur);
border-image-source: url(/media/diamonds.png);
src: url('fantasticfont.woff');
offset-path: url(#path);
mask-image: url("masks.svg#mask1");
}`)
let expected = `a {
background-image: url("star.gif");
list-style-image: url("../images/bullet.jpg");
content: url("pdficon.jpg");
cursor: url("mycursor.cur");
border-image-source: url("/media/diamonds.png");
src: url("fantasticfont.woff");
offset-path: url("#path");
mask-image: url("masks.svg#mask1");
}`
assert.is(actual, expected)
})

test.run()

0 comments on commit 3cc7c52

Please sign in to comment.