Skip to content

For , "0" should be parsed as number rather than length #15171

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
upsuper opened this issue Jan 24, 2017 · 12 comments · Fixed by #15278
Closed

For , "0" should be parsed as number rather than length #15171

upsuper opened this issue Jan 24, 2017 · 12 comments · Fixed by #15278
Labels
A-content/css Interacting with CSS from web content (parsing, serializing, introspection) C-assigned There is someone working on resolving the issue E-less-complex Straightforward. Recommended for a new contributor.

Comments

@upsuper
Copy link
Contributor

upsuper commented Jan 24, 2017

The plain zero can be parsed by both length and number, and there is no difference between either way in general. But for serialization, zero length would become 0px while zero number would stay 0, and the latter looks better as it doesn't changes, and you can always specify 0px to get the zero length.

This specific behavior is currently undefined in the spec (see w3c/csswg-drafts#489), but parsing plain zero as number matches all major browsers.

@upsuper
Copy link
Contributor Author

upsuper commented Jan 24, 2017

@upsuper upsuper added the E-less-complex Straightforward. Recommended for a new contributor. label Jan 24, 2017
@highfive
Copy link

Please make a comment here if you intend to work on this issue. Thank you!

@atheed
Copy link
Contributor

atheed commented Jan 24, 2017

May I claim this?
Full disclosure: I'm fairly new to Servo and Rust.

@jdm jdm added the A-content/css Interacting with CSS from web content (parsing, serializing, introspection) label Jan 24, 2017
@jdm
Copy link
Member

jdm commented Jan 24, 2017

@atheed Please do! Ask questions here if anything is unclear.

@upsuper upsuper added the C-assigned There is someone working on resolving the issue label Jan 25, 2017
@atheed
Copy link
Contributor

atheed commented Jan 25, 2017

I might be a little confused, but I'm not sure if the parse_non_negative in https://github.com/servo/servo/blob/master/components/style/values/specified/length.rs#L1142-L1148 is ever being called. For what CSS properties is that function supposed to be called? I've tried various lengths and numbers for various properties (font-size, padding, etc.), but none of them activate that ^ function.

@jdm
Copy link
Member

jdm commented Jan 25, 2017

It turns out that https://dxr.mozilla.org/servo/source/components/style/properties/longhand/border.mako.rs#263 is the only caller, and the border-image-outset property is only supported when using this code as part of Firefox (not the normal Servo binary), as evidenced by the product="gecko". However, we can write a unit test that exercises this code in tests/unit/style/parsing (run it with ./mach test-unit -p style).

@atheed
Copy link
Contributor

atheed commented Jan 25, 2017

Ah, I see -- thanks for the heads up!

@upsuper
Copy link
Contributor Author

upsuper commented Jan 25, 2017

Ah, actually I was thinking about line-height when I submitted this issue. It seems line-height uses a different path for parsing. The relevant code is https://github.com/servo/servo/blob/master/components/style/properties/longhand/inherited_text.mako.rs#L51

@atheed
Copy link
Contributor

atheed commented Jan 25, 2017

Ah, I see. So, this would be the relevant code for line-height https://github.com/servo/servo/blob/master/components/style/values/specified/length.rs#L897-L898, yes?
That said, it also does look like border-image-outset suffers from the same issue as line-height (i.e. the parsing of 0 as 0px instead of simply 0), so I can try to fix it for both.

@upsuper
Copy link
Contributor Author

upsuper commented Jan 26, 2017

Oh, I checked my list, and I was actually filing this for border-image-outset, but the same issue exists in line-height. I think the code for line-height is very specific in its own parsing code I mentioned above. That code tries to parse it as length first, and would happily accept 0. That code should be changed to try number first.

line-height's syntax is normal | | | , and I guess we don't want to add a new type LengthOrPercentageOrNumber for it... So I guess it should be enough to just change the parsing code of line-height.

@atheed
Copy link
Contributor

atheed commented Jan 27, 2017

Thanks.
I had a quick follow-up question: I've fixed the issue for both line-height and border-image-outset, and while I was writing unit tests for the new "0" behaviour for the latter (in https://github.com/servo/servo/blob/master/tests/unit/style/parsing/border.rs), I noticed that there don't appear to be any parsing unit tests for the former. As such, I was wondering where I should write the parsing unit tests for line-height for the new "0" behaviour -- should I write them in a new file?

@jdm
Copy link
Member

jdm commented Jan 27, 2017

The existing inherited_text.rs should be fine for that.

bors-servo pushed a commit that referenced this issue Jan 29, 2017
Parsing "0" as Number for line-height and border-image-outset

Fixes #15171 by correctly parsing `0` as `0` (rather than as `0px`, as was the case earlier) for the `line-height` and `border-image-outset` CSS properties. Wrote unit tests for both; `./mach test-unit -p style` passes all tests.

---

- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #15171


- [X] There are tests for these changes.




---
This change is [https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15278)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-content/css Interacting with CSS from web content (parsing, serializing, introspection) C-assigned There is someone working on resolving the issue E-less-complex Straightforward. Recommended for a new contributor.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants