New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a bug: css urls are incorrectly stripped of commas #14476
Fix a bug: css urls are incorrectly stripped of commas #14476
Conversation
.join(node.groups[0]?.type === "comma_group" ? "," : ""); | ||
.join(node.type === "paren_group" ? "," : ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 css Input: @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 <lionkay@gmail.com>
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
src/language-css/parser-postcss.js
Outdated
@@ -197,7 +194,6 @@ function parseNestedValue(node, options) { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also use this here.
getHighestAncestor(valueNode).text.slice( |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we trim here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought yes, at the first time.
But I feel I need to know CSS Specification more...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v3.2.1 seems good.
const { parse } = require('postcss-values-parser');
parse('url( https://example.com/\\(\\(.jpg )');
<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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last attempt by other maintainer. #11667
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Can you fix the conflicts? |
…correctly-stripped-of-commas-2
Good job @seiyab |
Co-authored-by: fisker Cheung <lionkay@gmail.com>
Description
Fix #14237
Checklist
(If changing the API or CLI) I’ve documented the changes I’ve made (in thedocs/
directory).changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨