Fix overflow in ::nth-child()

This commit is contained in:
Hiroyuki Ikezoe 2017-04-26 19:20:12 +09:00
parent e5762cb695
commit 1a37e69ce9

View file

@ -407,7 +407,7 @@ fn matches_generic_nth_child<E, F>(element: &E,
HAS_SLOW_SELECTOR_LATER_SIBLINGS HAS_SLOW_SELECTOR_LATER_SIBLINGS
}); });
let mut index = 1; let mut index: i32 = 1;
let mut next_sibling = if is_from_end { let mut next_sibling = if is_from_end {
element.next_sibling_element() element.next_sibling_element()
} else { } else {
@ -435,11 +435,13 @@ fn matches_generic_nth_child<E, F>(element: &E,
}; };
} }
if a == 0 { // Is there a non-negative integer n such that An+B=index?
b == index match index.checked_sub(b) {
} else { None => false,
(index - b) / a >= 0 && Some(an) => match an.checked_div(a) {
(index - b) % a == 0 Some(n) => n >= 0 && a * n == an,
None /* a == 0 */ => an == 0,
},
} }
} }