Fix a bug: css urls are incorrectly stripped of commas#14476
Fix a bug: css urls are incorrectly stripped of commas#14476fisker merged 24 commits intoprettier:mainfrom
Conversation
| const groups = node.groups | ||
| .map((currentValue) => stringifyNode(currentValue)) | ||
| .join(node.groups[0]?.type === "comma_group" ? "," : ""); | ||
| .join(node.type === "paren_group" ? "," : ""); |
There was a problem hiding this comment.
Commas had disappeard if the first comma group is flattened.
Groups in paren group should always be separated by comma.
Wrong link |
|
Can you try get original text instead of using Prettier pr-14476 --parser cssInput: @font-face {
src: url(foo.ttf?query=foo,bar,);
src: url(foo.woff2?foo=rgb(255,255,0));
}Output: @font-face {
src: url(foo.ttf?query=foo,bar);
src: url(foo.woff2?foo=rgb(255, 255, 0));
} |
Co-authored-by: fisker Cheung <[email protected]>
|
Thanks for pointing edge cases.
|
|
Trying to the original text isn't going smoothly.
I'm still trying 🚀 |
|
Following edge case still goes wrong... Input a {
content: url(https://example.com/\)\ \(.json);
}Output a {
content: url(https://example.com/\) \\(.json);
} |
|
↑postcss-value-parser seems to go wrong. Part of parse result against `url(https://example.com/\)\ \(.json)` |
220064f to
2ca6512
Compare
| parseNestedValue(node[key], options); | ||
| if (key === "nodes") { | ||
| node.group = flattenGroups(parseValueNode(node, options)); | ||
| delete node[key]; |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
|
I'm sorry for annoying commits. |
| * @param {*} node | ||
| * @returns {string} | ||
| */ | ||
| function stringifyFuncParam(node) { |
There was a problem hiding this comment.
We can also use this here.
I'll change it if you want.
|
Can I rerun CI? |
| content: url(https://example.com/\\ \\ .jpg); | ||
| content: url( https://example.com/\\)\\).jpg ); | ||
| content: url( https://example.com/\\(\\(.jpg ); | ||
| content: url(https://example.com/\\ \\ .jpg); |
There was a problem hiding this comment.
I thought yes, at the first time.
But I feel I need to know CSS Specification more...
There was a problem hiding this comment.
As I tested with in chrome
<style>
body {
background: url( 1.png?_= )
}
</style>
and
<style>
body {
background: url( 1.png )
}
</style>
They all requesting urls without space.
There was a problem hiding this comment.
postcss-values-parser throws.
I think it should be a bug.
I'll try newer versions.
const valueParser = require("postcss-values-parser");
valueParser('url( https://example.com/\\(\\(.jpg )', {loose: true}).parse()Uncaught ParserError: Expected closing parenthesis at line: 1, column 4
at Parser.error (~/Projects/oss/prettier/node_modules/postcss-values-parser/lib/parser.js:127:11)
at Parser.parenOpen (~/Projects/oss/prettier/node_modules/postcss-values-parser/lib/parser.js:279:12)
at Parser.parseTokens (~/Projects/oss/prettier/node_modules/postcss-values-parser/lib/parser.js:235:14)
at Parser.loop (~/Projects/oss/prettier/node_modules/postcss-values-parser/lib/parser.js:132:12)
at Parser.parse (~/Projects/oss/prettier/node_modules/postcss-values-parser/lib/parser.js:51:17)
There was a problem hiding this comment.
v3.2.1 seems good.
const { parse } = require('postcss-values-parser');
parse('url( https://example.com/\\(\\(.jpg )');Details
<ref *1> Root {
raws: { semicolon: false, after: '' },
type: 'root',
nodes: [
Func {
raws: [Object],
name: 'url',
type: 'func',
isColor: false,
isVar: false,
nodes: [Array],
parent: [Circular *1],
source: [Object],
params: '( https://example.com/\\(\\(.jpg )'
}
],
source: {
input: Input {
css: 'url( https://example.com/\\(\\(.jpg )',
hasBOM: false,
id: '<input css 1>'
},
start: { line: 1, column: 1 }
},
toString: [Function: bound toString]
}
But v3.0.0 is a big breaking release. https://github.com/shellscape/postcss-values-parser/releases
Which way do you like?
- Bump postcss-values-parser on next branch via another PR first, and then work on this bug.
- Leave
'url( https://example.com/\\(\\(.jpg )'and merge this PR first. And then try to bump postcss-values-parser on next branch. Finally, tackle'url( https://example.com/\\(\\(.jpg )'(or, perhaps it will be resolved by update).
There was a problem hiding this comment.
Will it conflict with your work if I'll try to bump postcss-value-parser?
Referring following, I'm asking you.
I want to make some change to the value-comma_group part
There was a problem hiding this comment.
No. Go a head, but it won't be easy, I've tried few times since maybe 2~3 years ago.
There was a problem hiding this comment.
Thank you for your replies.
Sounds so hard!
Any way, I'll try it, though I will be likely to give up 🔥
There was a problem hiding this comment.
@fisker
Hi, I have tried migrating postcss-values parser from v2 to v6.
Eventually, I gave up because shellscape/postcss-values-parser#140 prevents us from migrating.
May I summarize what I investigated for migration somewhere (perhaps an issue or a discussion)?
|
Can you fix the conflicts? |
…correctly-stripped-of-commas-2
|
Good job @seiyab |
Co-authored-by: fisker Cheung <[email protected]>
Description
Fix #14237
Checklist
(If changing the API or CLI) I’ve documented the changes I’ve made (in thedocs/directory).changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.✨Try the playground for this PR✨