Skip to content

Commit

Permalink
Fixed a case with & within a nested function in a declaration value (
Browse files Browse the repository at this point in the history
…#307)

* Add a failing test case for `&` within a nested function in a declaration value

* fix whitespace character unexpected inclusion

---------

Co-authored-by: Sultan <810601+thysultan@users.noreply.github.com>
  • Loading branch information
Andarist and thysultan committed Apr 26, 2023
1 parent bc0b1b0 commit d28ad01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function parse (value, root, parent, rule, rules, rulesets, pseudo, point
// \0 }
case 0: case 125: scanning = 0
// ;
case 59 + offset:
case 59 + offset: if (ampersand == -1) characters = replace(characters, /\f/g, '')
if (property > 0 && (strlen(characters) - length))
append(property > 32 ? declaration(characters + ';', rule, parent, length - 1) : declaration(replace(characters, ' ', '') + ';', rule, parent, length - 2), declarations)
break
Expand Down
12 changes: 11 additions & 1 deletion test/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ describe('Parser', () => {
).to.equal(`.user{color:red;}`)
})

test('& in value in a nested function', () => {
const urlOneX = "https://images.ctfassets.net/test.jpg?fm=webp&q=70&w=1000";
const urlTwoX = "https://images.ctfassets.net/test.jpg?fm=webp&q=70&w=2000";
expect(
stylis(`
background-image: image-set(url(${urlOneX}) 1x, url(${urlTwoX}) 2x);
`)
).to.equal(`.user{background-image:image-set(url(${urlOneX}) 1x, url(${urlTwoX}) 2x);}`)
})

test('& in a string', () => {
expect(
stylis(`
Expand All @@ -145,7 +155,7 @@ describe('Parser', () => {
'.user.\\@example\\.com{color:blue;}',
'.user.owner\\/founder{color:green;}',
// while double spaces after escaped hex codes need to be preserved,
// after an escaped character / code point it need not be preserved
// after an escaped character / code point it need not be preserved
'.user.discount\\%{color:purple;}'
].join(''))
});
Expand Down

0 comments on commit d28ad01

Please sign in to comment.