Skip to content
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 #273 and escaped selector sass-spec test #274

Merged
merged 4 commits into from Nov 18, 2020
Merged

Fix #273 and escaped selector sass-spec test #274

merged 4 commits into from Nov 18, 2020

Conversation

Cerdic
Copy link
Collaborator

@Cerdic Cerdic commented Nov 17, 2020

Escaped chars in selectors should not been systematically unescaped in the output, leading to unvalid selectors that the parser itself is refusing as valid.

For now we are keeping the escaped sequence in the selector, in a normalize way, to not take the risk to produce an unvalid selector

The target and safer should be to have the same way of managing escaping as in string and keyword: store the real char in a non escaped form in the selector representation, and escape in the output what should be escaped only.

But this require a better structure for representation of selectors out of the parser, otherwise this would more or less implie to reparse in the compiler to know what to escape, which would be a shame
(ie for instance escape non alpha first chars of identifiers and non allowed chars in identifier, but without escaping attributes content matching)

…unescaped in the output, leading to unvalid selectors that the parser itself is refusing as valid.

For now we are keeping the escaped sequence in the selector, in a normalize way, to not take the risk to produce an unvalid selector
The target and safer should be to have the same way of managing escpaing as in string and keyword:
store the real char in a non escaped form in the selector representation, and escape in the output what should be escaped only.

But this require a better structure for representation of selectors out of the parser, otherwise this would more or less implie to reparse in the compiler to know what to escape, which would be a shame
(ie for instance escape non alpha first chars of identifiers and non allowed chars in identifier, but without escaping attributes content matching)
src/Compiler.php Outdated
if ($parser->parseSelector($buffer, $newSelectors, true)) {
try {
$isValid = $parser->parseSelector($buffer, $newSelectors, true);
} catch (\Exception $e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should catch only ParserException IMO

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

.\31 u\24 { clear: right;}
.a\31 u\24 { clear: both;}
$x: '\\28' + 'xlarge' + '\\29';
.\31 2u#{$x}, .\31 2u\24#{$x} { width: 100%; clear: none; margin-left: 0; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that we also contribute upstream to have tests covering that in sass-spec, instead of covering them only in our own testsuite (see #179)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with sass/sass-spec#1600
Let's see how the processus is working.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cerdic any plan to take their review into account ?

@Cerdic
Copy link
Collaborator Author

Cerdic commented Nov 18, 2020

I made the corrections, and I had to correct the patch to be fully compliant on the draft spec I sent as a PR on sass-spec , as dart-sass unescape numbers if not at the first char.

Again, the fix is not a definitive fix, and I'm quite sure that pushing a bit on combination of escape sequence and position of the escape sequence you could find other cases where scssphp will keep the escape sequence and not dart-sass.

But at least, this is a safe fix as the final selector should always be as valid as the input selector - If I did no mistake.
To be followed when we improved the selector parsing and abstract representation

@stof
Copy link
Member

stof commented Nov 18, 2020

keeping more escape sequences is OK, if the output is equivalent CSS

@Cerdic Cerdic merged commit 417ec6e into master Nov 18, 2020
@Cerdic Cerdic deleted the fix-issue-273 branch November 18, 2020 16:25
@stof stof added this to the 1.4.1 milestone Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants