aboutsummaryrefslogtreecommitdiffstats
path: root/components/util/str.rs
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2015-12-21 19:49:30 -0800
committerCorey Farwell <coreyf@rwell.org>2015-12-24 13:20:43 -0800
commitba659cb99cd07ca93736e44226bf164dd7f01088 (patch)
treed9898cccc51298e0dfd4e7321e892e992acb933d /components/util/str.rs
parentdafdc856ac3fc2bd000e61bdcaed2c024828de0c (diff)
downloadservo-ba659cb99cd07ca93736e44226bf164dd7f01088.tar.gz
servo-ba659cb99cd07ca93736e44226bf164dd7f01088.zip
Implement non-zero dimension attribute parsing
Fixes #8445 The only attributes I found that we have implemented that uses non-zero dimenion attributes: * `width` for `<td>` and `<th>` (table cells) * `width` for `<table>` I updated these implementations to use the new non-zero dimension attribute parsing and added associated regression tests.
Diffstat (limited to 'components/util/str.rs')
-rw-r--r--components/util/str.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/components/util/str.rs b/components/util/str.rs
index 9978464ee0d..f00dd8e3ea7 100644
--- a/components/util/str.rs
+++ b/components/util/str.rs
@@ -4,6 +4,7 @@
use app_units::Au;
use cssparser::{self, Color, RGBA};
+use euclid::num::Zero;
use js::conversions::{FromJSValConvertible, ToJSValConvertible, latin1_to_string};
use js::jsapi::{JSContext, JSString, HandleValue, MutableHandleValue};
use js::jsapi::{JS_GetTwoByteStringCharsAndLength, JS_StringHasLatin1Chars};
@@ -372,6 +373,17 @@ pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
}
}
+/// HTML5 § 2.4.4.5.
+///
+/// https://html.spec.whatwg.org/multipage/#rules-for-parsing-non-zero-dimension-values
+pub fn parse_nonzero_length(value: &str) -> LengthOrPercentageOrAuto {
+ match parse_length(value) {
+ LengthOrPercentageOrAuto::Length(x) if x == Au::zero() => LengthOrPercentageOrAuto::Auto,
+ LengthOrPercentageOrAuto::Percentage(0.) => LengthOrPercentageOrAuto::Auto,
+ x => x,
+ }
+}
+
/// https://html.spec.whatwg.org/multipage/#rules-for-parsing-a-legacy-font-size
pub fn parse_legacy_font_size(mut input: &str) -> Option<&'static str> {
// Steps 1 & 2 are not relevant