Skip to content

[css-syntax] Correctly handle "escaped EOF" #3182

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

Closed
tabatkins opened this issue Sep 28, 2018 · 10 comments
Closed

[css-syntax] Correctly handle "escaped EOF" #3182

tabatkins opened this issue Sep 28, 2018 · 10 comments
Labels
Closed Accepted by CSSWG Resolution Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. css-syntax-3 Tested Memory aid - issue has WPT tests

Comments

@tabatkins
Copy link
Member

Per our June 2013 resolution (recorded in #3174), the correct way to handle an "escaped EOF" (that is, a stylesheet ending in a \) is to produce a U+FFFD, except in strings, where it is ignored.

Currently, Syntax correctly specifies that you ignore an escaped EOF in a string, but for anything else, it ends the current token, then reconsumes the \ as a fresh token, which ends up producing a DELIM token containing \.

It looks like I can't just simply modify that clause in "Consume a token", because implementations don't end the preceding token.

Test case:

<!DOCTYPE html>
<style>.foo {--foo:foo\</style>
<style>.foo {--foo:foo \</style>
<style>.foo {--foo:"foo\</style>
<script>
for(var sheet of document.styleSheets) {
  w(sheet.cssRules[0].cssText);
}
</script>
@tabatkins
Copy link
Member Author

Current behavior of the testcase:

Chrome

log: .foo { --foo:foo�; }
log: .foo { --foo:foo �; }
log: .foo { --foo:"foo"; }

Safari

log: .foo { --foo: foo�; }
log: .foo { --foo: foo �; }
log: .foo { --foo: "foo"; }

Firefox

log: .foo { --foo:foo\�; }
log: .foo { --foo:foo \�; }
log: .foo { --foo:"foo"; }

Edge

log: .foo { --foo:foo\; }
log: .foo { --foo:foo \; }
log: .foo { --foo:“foo\; }

(Yes, Edge really printed these, every single one of which isn't even remotely correct.)


So, Edge is clearly super-wrong. Chrome and Safari agree, and obey the old resolution. (How they did so, when the spec doesn't say to do that, I'm not sure...) Firefox obeys the resolution, but unnecessarily escapes the U+FFFD when serializing.

Darn, I was hoping somebody implemented the thing I already had specced, so I didn't have to change anything. ^_^

@tabatkins
Copy link
Member Author

...huh. Plugging the first test-case into the dingus, I get the same result as Chrome/WebKit (a U+FFFD that doesn't interrupt the token). This suggests that I changed the spec at some point to the current text. I'll have to research why I did this.

@tabatkins
Copy link
Member Author

Ah, found it: #1821

I was trying to fix #-\EOF getting recognized as an ident, but looking at impls, they do indeed treat that as an ident type. (The dingus doesn't, so that's a bug...) I just need to revert that "fix".

@tabatkins
Copy link
Member Author

Agenda+ to verify I can fix this. The fix is that an "escaped EOF" (aka a \ at the end of a stylesheet) should return U+FFFD, not a \ as the spec currently mandates. (Except in strings, where it's just silently ignored.) This matches all browsers now that Edge is going away - the only difference is that Firefox serializes such an EOF differently than Chrome/WebKit. (But that's not a Syntax problem, it's a CSSOM problem.)

A side effect of this is that ending a stylesheet with -\EOF will create an ident. This matches browser behavior, so it should be fine.

@css-meeting-bot
Copy link
Member

The CSS Working Group just discussed Correctly handle "escaped EOF", and agreed to the following:

  • RESOLVED: Change syntax to specify behavior impl in majority of browsers
The full IRC log of that discussion <dael> Topic: Correctly handle "escaped EOF"
<dael> github: https://github.com//issues/3182#issuecomment-455376948
<dael> TabAtkins: The spec for syntax- this is a weird corner issue and I'm going to match impl. Turns out the way impl handle an escaped end of file is to omit a replacement character
<dael> TabAtkins: Resolved this at one point, but resolutions are confusing. Spec doesn't say that right now. A slash at the end of the file doesn't create an escape as per spec. FF, Chrome, and Safari think it counts as an escape for replaced character. Want to edt spec to match impl.
<dael> TabAtkins: Edge does extremely wrong things for the slash so I don't think we can draw from that.
<TabAtkins> https://github.com//issues/3182#issuecomment-426019418
<dael> TabAtkins: This is what they do ^
<dael> TabAtkins: I can't tell what they're doing internally, the serialized isn't round trip-able
<dael> TabAtkins: Only difference in other browsers is FF serializes it as an escape for itself which is same result as omitting. It's a CSSOM serialization issue. syntax-relevent has all browsers behaving the same
<dael> astearns: Concerns?
<dael> Rossen: I haven't had a chance to look. Reading through TabAtkins 's comments. I won't push back, but I'm curious what we're doing. I'll comment if I want to re-open.
<dael> astearns: You're fine resolution now?
<dael> Rossen: Yep. Just like any other issue
<dael> astearns: Objections to changing syntax to spec behavior impl in majority of browsers?
<dael> RESOLVED: Change syntax to specify behavior impl in majority of browsers

@emilio
Copy link
Collaborator

emilio commented Jan 23, 2019

It would be amazing to add a WPT for this if we specify it.

@tabatkins
Copy link
Member Author

Yup def. I pushed a few updates last week when closing out issues that I need to write WPTs for too; I'll do that this week.

(For that matter, I think y'all's serialization implementation is wrong here, and will cause you to spuriously fail the test I would write for this issue.)

@emilio
Copy link
Collaborator

emilio commented Jan 23, 2019

Hmm, why? The serialization roundtrips, doesn't it? cc @SimonSapin

@tabatkins
Copy link
Member Author

It roundtrips, yeah, but the escape is unnecessary. Everything outside of ASCII range is fine to be emitted directly; escaping it is basically a no-op.

There's nothing in CSSOM's serialization rules that say to escape that character.

tabatkins added a commit to web-platform-tests/wpt that referenced this issue Jan 26, 2019
@tabatkins tabatkins added Closed Accepted by CSSWG Resolution Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. Tested Memory aid - issue has WPT tests labels Jan 26, 2019
@tabatkins
Copy link
Member Author

All right, fix committed in spec, and test will be committed as soon as Travis cycles.

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Feb 5, 2019
Automatic update from web-platform-tests
Escaped EOF

Tests <w3c/csswg-drafts#3182> and <w3c/csswg-drafts#1821>
--
Use assert_throws, etc

Per @domenic's advice, go ahead and use assert_throws on the throwing call, and then just make the should-succeed call directly, as a throw will cause the test to fail anyway.
--
Merge pull request #15092 from web-platform-tests/tabatkins-patch-1

Escaped EOF

--

wpt-commits: 26f39eb230185a804fabc398810cdcdddefc49ac, f44998b147858a8a2832f66dd32bc9d1ecefb1b3, fc57d7ad7a2942cfa363d5a9b8c6c7d74f5bb693
wpt-pr: 15092
mykmelez pushed a commit to mykmelez/gecko that referenced this issue Feb 6, 2019
Automatic update from web-platform-tests
Escaped EOF

Tests <w3c/csswg-drafts#3182> and <w3c/csswg-drafts#1821>
--
Use assert_throws, etc

Per @domenic's advice, go ahead and use assert_throws on the throwing call, and then just make the should-succeed call directly, as a throw will cause the test to fail anyway.
--
Merge pull request #15092 from web-platform-tests/tabatkins-patch-1

Escaped EOF

--

wpt-commits: 26f39eb230185a804fabc398810cdcdddefc49ac, f44998b147858a8a2832f66dd32bc9d1ecefb1b3, fc57d7ad7a2942cfa363d5a9b8c6c7d74f5bb693
wpt-pr: 15092
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Feb 7, 2019
Automatic update from web-platform-tests
Escaped EOF

Tests <w3c/csswg-drafts#3182> and <w3c/csswg-drafts#1821>
--
Use assert_throws, etc

Per @domenic's advice, go ahead and use assert_throws on the throwing call, and then just make the should-succeed call directly, as a throw will cause the test to fail anyway.
--
Merge pull request #15092 from web-platform-tests/tabatkins-patch-1

Escaped EOF

--

wpt-commits: 26f39eb230185a804fabc398810cdcdddefc49ac, f44998b147858a8a2832f66dd32bc9d1ecefb1b3, fc57d7ad7a2942cfa363d5a9b8c6c7d74f5bb693
wpt-pr: 15092
mykmelez pushed a commit to mykmelez/gecko that referenced this issue Feb 8, 2019
Automatic update from web-platform-tests
Escaped EOF

Tests <w3c/csswg-drafts#3182> and <w3c/csswg-drafts#1821>
--
Use assert_throws, etc

Per @domenic's advice, go ahead and use assert_throws on the throwing call, and then just make the should-succeed call directly, as a throw will cause the test to fail anyway.
--
Merge pull request #15092 from web-platform-tests/tabatkins-patch-1

Escaped EOF

--

wpt-commits: 26f39eb230185a804fabc398810cdcdddefc49ac, f44998b147858a8a2832f66dd32bc9d1ecefb1b3, fc57d7ad7a2942cfa363d5a9b8c6c7d74f5bb693
wpt-pr: 15092
@tabatkins tabatkins added this to the CSS Syntax 3 June 2019 CR milestone Jun 28, 2019
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Oct 3, 2019
Automatic update from web-platform-tests
Escaped EOF

Tests <w3c/csswg-drafts#3182> and <w3c/csswg-drafts#1821>
--
Use assert_throws, etc

Per domenic's advice, go ahead and use assert_throws on the throwing call, and then just make the should-succeed call directly, as a throw will cause the test to fail anyway.
--
Merge pull request #15092 from web-platform-tests/tabatkins-patch-1

Escaped EOF

--

wpt-commits: 26f39eb230185a804fabc398810cdcdddefc49ac, f44998b147858a8a2832f66dd32bc9d1ecefb1b3, fc57d7ad7a2942cfa363d5a9b8c6c7d74f5bb693
wpt-pr: 15092

UltraBlame original commit: 899781fedf2c2dbc671c092a82bd6928af567075
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Oct 3, 2019
Automatic update from web-platform-tests
Escaped EOF

Tests <w3c/csswg-drafts#3182> and <w3c/csswg-drafts#1821>
--
Use assert_throws, etc

Per domenic's advice, go ahead and use assert_throws on the throwing call, and then just make the should-succeed call directly, as a throw will cause the test to fail anyway.
--
Merge pull request #15092 from web-platform-tests/tabatkins-patch-1

Escaped EOF

--

wpt-commits: 26f39eb230185a804fabc398810cdcdddefc49ac, f44998b147858a8a2832f66dd32bc9d1ecefb1b3, fc57d7ad7a2942cfa363d5a9b8c6c7d74f5bb693
wpt-pr: 15092

UltraBlame original commit: 21afd416b4906b2b0ff3745ad10cde023c36c46b
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Oct 3, 2019
Automatic update from web-platform-tests
Escaped EOF

Tests <w3c/csswg-drafts#3182> and <w3c/csswg-drafts#1821>
--
Use assert_throws, etc

Per domenic's advice, go ahead and use assert_throws on the throwing call, and then just make the should-succeed call directly, as a throw will cause the test to fail anyway.
--
Merge pull request #15092 from web-platform-tests/tabatkins-patch-1

Escaped EOF

--

wpt-commits: 26f39eb230185a804fabc398810cdcdddefc49ac, f44998b147858a8a2832f66dd32bc9d1ecefb1b3, fc57d7ad7a2942cfa363d5a9b8c6c7d74f5bb693
wpt-pr: 15092

UltraBlame original commit: 899781fedf2c2dbc671c092a82bd6928af567075
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Oct 3, 2019
Automatic update from web-platform-tests
Escaped EOF

Tests <w3c/csswg-drafts#3182> and <w3c/csswg-drafts#1821>
--
Use assert_throws, etc

Per domenic's advice, go ahead and use assert_throws on the throwing call, and then just make the should-succeed call directly, as a throw will cause the test to fail anyway.
--
Merge pull request #15092 from web-platform-tests/tabatkins-patch-1

Escaped EOF

--

wpt-commits: 26f39eb230185a804fabc398810cdcdddefc49ac, f44998b147858a8a2832f66dd32bc9d1ecefb1b3, fc57d7ad7a2942cfa363d5a9b8c6c7d74f5bb693
wpt-pr: 15092

UltraBlame original commit: 21afd416b4906b2b0ff3745ad10cde023c36c46b
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Oct 4, 2019
Automatic update from web-platform-tests
Escaped EOF

Tests <w3c/csswg-drafts#3182> and <w3c/csswg-drafts#1821>
--
Use assert_throws, etc

Per domenic's advice, go ahead and use assert_throws on the throwing call, and then just make the should-succeed call directly, as a throw will cause the test to fail anyway.
--
Merge pull request #15092 from web-platform-tests/tabatkins-patch-1

Escaped EOF

--

wpt-commits: 26f39eb230185a804fabc398810cdcdddefc49ac, f44998b147858a8a2832f66dd32bc9d1ecefb1b3, fc57d7ad7a2942cfa363d5a9b8c6c7d74f5bb693
wpt-pr: 15092

UltraBlame original commit: 899781fedf2c2dbc671c092a82bd6928af567075
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Oct 4, 2019
Automatic update from web-platform-tests
Escaped EOF

Tests <w3c/csswg-drafts#3182> and <w3c/csswg-drafts#1821>
--
Use assert_throws, etc

Per domenic's advice, go ahead and use assert_throws on the throwing call, and then just make the should-succeed call directly, as a throw will cause the test to fail anyway.
--
Merge pull request #15092 from web-platform-tests/tabatkins-patch-1

Escaped EOF

--

wpt-commits: 26f39eb230185a804fabc398810cdcdddefc49ac, f44998b147858a8a2832f66dd32bc9d1ecefb1b3, fc57d7ad7a2942cfa363d5a9b8c6c7d74f5bb693
wpt-pr: 15092

UltraBlame original commit: 21afd416b4906b2b0ff3745ad10cde023c36c46b
bhearsum pushed a commit to mozilla-releng/staging-firefox that referenced this issue May 1, 2025
Automatic update from web-platform-tests
Escaped EOF

Tests <w3c/csswg-drafts#3182> and <w3c/csswg-drafts#1821>
--
Use assert_throws, etc

Per @domenic's advice, go ahead and use assert_throws on the throwing call, and then just make the should-succeed call directly, as a throw will cause the test to fail anyway.
--
Merge pull request #15092 from web-platform-tests/tabatkins-patch-1

Escaped EOF

--

wpt-commits: 26f39eb230185a804fabc398810cdcdddefc49ac, f44998b147858a8a2832f66dd32bc9d1ecefb1b3, fc57d7ad7a2942cfa363d5a9b8c6c7d74f5bb693
wpt-pr: 15092
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed Accepted by CSSWG Resolution Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. css-syntax-3 Tested Memory aid - issue has WPT tests
Projects
None yet
Development

No branches or pull requests

3 participants