Makes setting negative values to maxLength throw an IndexSize exception

This commit is contained in:
Sam Gibson 2015-12-02 13:35:05 +11:00
parent 51ca659f8a
commit 9668500e97
7 changed files with 75 additions and 15 deletions

View file

@ -5,8 +5,8 @@
use cssparser::RGBA;
use std::ops::Deref;
use string_cache::{Atom, Namespace};
use util::str::{DOMString, LengthOrPercentageOrAuto, parse_integer, parse_unsigned_integer, parse_legacy_color, parse_length};
use util::str::{split_html_space_chars, str_join};
use util::str::{DOMString, LengthOrPercentageOrAuto, parse_unsigned_integer, parse_legacy_color, parse_length};
use util::str::{split_html_space_chars, str_join, parse_integer};
use values::specified::{Length};
// Duplicated from script::dom::values.
@ -53,12 +53,22 @@ impl AttrValue {
AttrValue::UInt(string, result)
}
// https://html.spec.whatwg.org/multipage/infrastructure.html#limited-to-only-non-negative-numbers
pub fn from_i32(string: DOMString, default: i32) -> AttrValue {
let result = parse_integer(string.chars()).unwrap_or(default);
AttrValue::Int(string, result)
}
// https://html.spec.whatwg.org/multipage/#limited-to-only-non-negative-numbers
pub fn from_limited_i32(string: DOMString, default: i32) -> AttrValue {
let result = parse_integer(string.chars()).unwrap_or(default);
if result < 0 {
AttrValue::Int(string, default)
} else {
AttrValue::Int(string, result)
}
}
// https://html.spec.whatwg.org/multipage/#limited-to-only-non-negative-numbers-greater-than-zero
pub fn from_limited_u32(string: DOMString, default: u32) -> AttrValue {
let result = parse_unsigned_integer(string.chars()).unwrap_or(default);