Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upTreat top-level number in calc() invalid #14421
Conversation
highfive
commented
Nov 30, 2016
highfive
commented
Nov 30, 2016
|
This should probably have a test... |
|
Test added. |
|
r? @emilio |
| @@ -576,7 +576,6 @@ impl CalcLengthOrPercentage { | |||
| let mut ch = None; | |||
| let mut rem = None; | |||
| let mut percentage = None; | |||
| let mut number = None; | |||
This comment has been minimized.
This comment has been minimized.
dzbarsky
Dec 2, 2016
Member
have you tested what other browsers do? I remember this bit being weird and inconsistent between browsers. In particular, Firefox doesn't get calc right.
This comment has been minimized.
This comment has been minimized.
upsuper
Dec 2, 2016
•
Author
Member
Firefox didn't get calc() right for properties which support numbers (particular line-height), but people are fixing that.
Not returning number as part of the result but treating it valid make no sense anyway. For properties which doesn't accept numbers, it is pretty consistent between browsers to reject calc() contains top level numbers. You can try this testcase:
<!DOCTYPE html>
<style>
div {
width: 1px;
width: calc(5); /* invalid */
width: calc(10 + 20px); /* invalid */
}
</style>
<script>
document.write(document.styleSheets[0].cssRules[0].style.width);
</script>It would likely crash Servo because of serializing empty calc(). See the stack backtrace in bug 1321206.
|
r=me with that. |
| @@ -606,7 +605,6 @@ impl CalcLengthOrPercentage { | |||
| FontRelativeLength::Rem(val) => | |||
| rem = Some(rem.unwrap_or(0.) + val), | |||
| }, | |||
This comment has been minimized.
This comment has been minimized.
|
@bors-servo delegate+ |
|
|
Currently, CalcLengthOrPercentage doesn't actually keep the number value, so if we don't treat it invalid, we can end up generating empty `calc()` value when one contains top-level numbers (e.g. `calc(1)`), which would violate assertion elsewhere that `calc` must not be empty.
|
@bors-servo r=emilio |
|
|
Treat top-level number in calc() invalid <!-- Please describe your changes on the following line: --> This should probably considered as a temporary fix (for [bug 1321206](https://bugzilla.mozilla.org/show_bug.cgi?id=1321206)), to avoid assertion when trying to serialize calc value with only numbers. Certain properties (e.g. `line-height`) would eventually need to keep numbers inside calc. --- <!-- 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 - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Currently, CalcLengthOrPercentage doesn't actually keep the number value. If we don't treat it invalid, we can end up generating empty `calc()` value when one contains numbers (e.g. `calc(1)`), which would violate assertion elsewhere that `calc` must not be empty. <!-- 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/14421) <!-- Reviewable:end -->
|
|
|
|
@bors-servo retry |
Treat top-level number in calc() invalid <!-- Please describe your changes on the following line: --> This should probably considered as a temporary fix (for [bug 1321206](https://bugzilla.mozilla.org/show_bug.cgi?id=1321206)), to avoid assertion when trying to serialize calc value with only numbers. Certain properties (e.g. `line-height`) would eventually need to keep numbers inside calc. --- <!-- 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 - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Currently, CalcLengthOrPercentage doesn't actually keep the number value. If we don't treat it invalid, we can end up generating empty `calc()` value when one contains numbers (e.g. `calc(1)`), which would violate assertion elsewhere that `calc` must not be empty. <!-- 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/14421) <!-- Reviewable:end -->
|
|
upsuper commentedNov 30, 2016
•
edited
This should probably considered as a temporary fix (for bug 1321206), to avoid assertion when trying to serialize calc value with only numbers. Certain properties (e.g.
line-height) would eventually need to keep numbers inside calc../mach build -ddoes not report any errors./mach test-tidydoes not report any errorsCurrently, CalcLengthOrPercentage doesn't actually keep the number value. If we don't treat it invalid, we can end up generating empty
calc()value when one contains numbers (e.g.calc(1)), which would violate assertion elsewhere thatcalcmust not be empty.This change is