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

Support line number offsets for inline stylesheets #15693

Closed
jdm opened this issue Feb 22, 2017 · 16 comments
Closed

Support line number offsets for inline stylesheets #15693

jdm opened this issue Feb 22, 2017 · 16 comments

Comments

@jdm
Copy link
Member

@jdm jdm commented Feb 22, 2017

The DOM-side work will be very similar to the work in #14963.

@jdm
Copy link
Member Author

@jdm jdm commented Feb 23, 2017

The CSS parser work will require:

  • adding a way to create a Parser with a given starting line number
  • using that to create a Tokenizer with the starting line (and resetting it later)
@jdm
Copy link
Member Author

@jdm jdm commented Feb 23, 2017

On the other hand, we could avoid touching the CSS parser at all and store the offset in ParserContext, and pass it as an argument to the report_error API instead. That's an easier plan.

@nox
Copy link
Member

@nox nox commented Feb 23, 2017

Claiming this one for a contributor.

@nox nox added the C-assigned label Feb 23, 2017
@PratikDhanave
Copy link

@PratikDhanave PratikDhanave commented Feb 23, 2017

I am working on it.

@jdm
Copy link
Member Author

@jdm jdm commented Mar 16, 2017

@PratikDhanave Have you made any progress? Any questions?

@PratikDhanave
Copy link

@PratikDhanave PratikDhanave commented Mar 16, 2017

@jdm jdm removed the C-assigned label Mar 27, 2017
@jdm
Copy link
Member Author

@jdm jdm commented Mar 27, 2017

Unassigning due to lack of activity.

@jdm jdm added the E-less easy label Mar 27, 2017
@jdm
Copy link
Member Author

@jdm jdm commented Mar 27, 2017

Necessary work:

  • store the offset in ParserContext, add a new offset argument to report_error
  • add a new offset argument to ParserContext::new_with_extra_data, as well as Stylesheet::parse_rules and Stylesheet::from_str
  • store the line number in HTMLStyleElement, obtained via the ElementCreator value that is present in the new_inherited method
  • pass this line number as the offset when calling Stylesheet::from_str in HTMLStyleElement::parse_own_stylesheet

Code: components/script/htmlstyleelement.rs, components/style/parser.rs, components/style/stylesheets.rs, components/style/error_reporting.rs

@jdm
Copy link
Member Author

@jdm jdm commented Mar 27, 2017

The idea here is that we get incorrect line numbers in HTML like this:











<style>
:matches(thead)[align=absmiddle i] {
  color: red
}
</style>

If we run RUST_LOG=script_layout_interface::reporter ./mach run file.html, we see:

INFO:script_layout_interface::reporter: Url:    file:///tmp/style.html
2:1 Invalid rule: ':matches(thead)[align=absmiddle i] {'

when the invalid CSS is clearly not line 2 of the actual file.

@SimonSapin
Copy link
Member

@SimonSapin SimonSapin commented Mar 27, 2017

Maybe also a column offset, for the first line? Especially for style attributes.

@jdm
Copy link
Member Author

@jdm jdm commented Mar 27, 2017

I think that will require additional changes to html5ever. Let's keep this focused on line offsets for now.

@SimonSapin
Copy link
Member

@SimonSapin SimonSapin commented Mar 27, 2017

Also counting "columns" is more tricky than it seems. UTF-8 bytes v.s. code points v.s. grapheme clusters v.s. east-asian width… Deferring for now avoids this question.

@mckaymatt
Copy link
Contributor

@mckaymatt mckaymatt commented Apr 5, 2017

@highfive: assign me

@highfive
Copy link

@highfive highfive commented Apr 5, 2017

Hey @mckaymatt! Thanks for your interest in working on this issue. It's now assigned to you!

@highfive highfive added the C-assigned label Apr 5, 2017
@mckaymatt
Copy link
Contributor

@mckaymatt mckaymatt commented Apr 12, 2017

@jdm when you say

pass this line number as the offset when calling Stylesheet::from_str in HTMLStyleElement::parse_own_stylesheet

Do you mean HTMLStyleElement::parse_own_css?

@jdm
Copy link
Member Author

@jdm jdm commented Apr 12, 2017

Yes.

bors-servo added a commit that referenced this issue Apr 13, 2017
…nSapin

Support line number offsets for inline stylesheets

<!-- Please describe your changes on the following line: -->
This allows accurate line numbers when reporting stylesheet errors.

@jdm This is going to require some effort to merge my changes with other recent changes to `ParserContext`. Because of that I would appreciate a quick sanity check before I put the time into performing the merge.
For example, should I store the `offset` as a u64, or should it be an Option?

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #15693 (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16394)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Apr 14, 2017
…nSapin

Support line number offsets for inline stylesheets

<!-- Please describe your changes on the following line: -->
This allows accurate line numbers when reporting stylesheet errors.

@jdm This is going to require some effort to merge my changes with other recent changes to `ParserContext`. Because of that I would appreciate a quick sanity check before I put the time into performing the merge.
For example, should I store the `offset` as a u64, or should it be an Option?

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #15693 (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16394)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

6 participants
You can’t perform that action at this time.