Closed Bug 384672 Opened 17 years ago Closed 13 years ago

Escaped newline handling should be limited to strings

Categories

(Core :: CSS Parsing and Computation, defect, P4)

defect

Tracking

()

RESOLVED FIXED
mozilla6

People

(Reporter: sharparrow1, Assigned: dbaron)

References

(Blocks 1 open bug, )

Details

Attachments

(5 files, 1 obsolete file)

Take a rule like the following:

background: r\
gb(0,0,0);

Mozilla accepts this as a background declaration, but according to the CSS rules escaped newlines are only ignored in strings.

This does bring about the interesting side question of whether the following:

<style>
.a\
{color: red}
</style>
<div class="a\">a</div>

should result in a red a. (Opera tosses out the whole rule; in IE, the rule matches class "a" following some logic which doesn't seem completely consistent.)
Answering myself: I'm pretty sure that backslash followed by a newline outside a string should result in a malformed declaration according to the CSS rules.
Are other browsers that handle escaped newlines in strings ignoring them outside of strings, or should we just change the spec to match the implementations?
IE's usually, but not always, treats it as some sort of parse error. However, it sometimes ignores the backslash if it's at the end of a token.

Opera consistently treats a backslash followed by a newline outside of a string as a parse error.

Safari also seems to treat this case as a parse error; I haven't tested thoroughly, though.

I think we're the only implementation that handles backslash newline escapes outside of strings.
Addendum:
gecko removes improperly the \00000a within the string.

see:
http://samples.msdn.microsoft.com/csstestpages/Chapter_4/escaped-newline-001.htm
(In reply to comment #4)
> Addendum:
> gecko removes improperly the \00000a within the string.

Nothing to do with this bug, and see the comments about white-space defaults on :before and :after on public-css-testsuite and www-style right after Microsoft's tests were contributed. (http://lists.w3.org/Archives/Public/)
> backslash followed by a newline outside
> a string should result in a malformed declaration according to the CSS rules

This is also the conclusion we reached here:

[CSS2.1] Clarification on section 4.1.3 and the application of escaped newlines to identifiers
http://lists.w3.org/Archives/Public/www-style/2008Nov/0035.html

Zack Weinberg, Boris Zbarsky and fantasai participated into such discussion.

> DIV
> {
> background-color: gre\
> en;
> }

> There is a note that only FireFox currently supports this behavior, 
> which I believe makes them non-compliant.

"Yeah, the Gecko behavior here is just wrong.  We'll fix it." B. Zbarsky
The working group discussed this today, and I don't think things were so clear-cut.
Summary: Escaped newlines ignored in identifiers → Escaped newline handling should be limited to strings
Assignee: nobody → dbaron
Status: NEW → ASSIGNED
OS: Windows XP → All
Priority: -- → P4
Hardware: x86 → All
Target Milestone: --- → mozilla6
Comment on attachment 529382 [details] [diff] [review]
patch 1: pass in-string boolean to ParseAndAppendEscape

r=me
Attachment #529382 - Flags: review?(bzbarsky) → review+
Comment on attachment 529383 [details] [diff] [review]
patch 2: handle failure of GatherIdent and fix up ParseRef

>Handle failure of GatherIdent, which can happen (starting with the next patch) fail

  s/happen //

or otherwise fix the grammar.

r=me with that.
Attachment #529383 - Flags: review?(bzbarsky) → review+
Comment on attachment 529384 [details] [diff] [review]
patch 3: introduce failure from ParseAndAppendEscape in the EOF cases, and handle that failure

r=me
Attachment #529384 - Flags: review?(bzbarsky) → review+
Comment on attachment 529385 [details] [diff] [review]
patch 4: only allow escaped newlines within strings (string token and string in url() token)

Hmm.  Why do you not need to push back ch in the !aInString case?  And won't this tokenize escaped newline as DELIM for the '\\' and then whitespace?
Comment on attachment 529386 [details] [diff] [review]
patch 5: fix the remaining todo in test_parse_rule.html, a test error

r=me
Attachment #529386 - Flags: review?(bzbarsky) → review+
(In reply to comment #17)
> Comment on attachment 529385 [details] [diff] [review] [review]
> patch 4: only allow escaped newlines within strings (string token and string in
> url() token)
> 
> Hmm.  Why do you not need to push back ch in the !aInString case?  And won't
> this tokenize escaped newline as DELIM for the '\\' and then whitespace?

Er, right, I do need a Pushback() there; without that I'd fail to tokenize the whitespace.  I'm not sure how the difference is testable, though, since we still generate the delim token (per patch 3), and that should cause any parser caller I can think of to fail.
Comment on attachment 529796 [details] [diff] [review]
patch 4: only allow escaped newlines within strings (string token and string in url() token)

r=me
Attachment #529796 - Flags: review?(bzbarsky) → review+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: