mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Fix overflow in ::nth-child()
This commit is contained in:
parent
e5762cb695
commit
1a37e69ce9
1 changed files with 8 additions and 6 deletions
|
@ -407,7 +407,7 @@ fn matches_generic_nth_child<E, F>(element: &E,
|
|||
HAS_SLOW_SELECTOR_LATER_SIBLINGS
|
||||
});
|
||||
|
||||
let mut index = 1;
|
||||
let mut index: i32 = 1;
|
||||
let mut next_sibling = if is_from_end {
|
||||
element.next_sibling_element()
|
||||
} else {
|
||||
|
@ -435,11 +435,13 @@ fn matches_generic_nth_child<E, F>(element: &E,
|
|||
};
|
||||
}
|
||||
|
||||
if a == 0 {
|
||||
b == index
|
||||
} else {
|
||||
(index - b) / a >= 0 &&
|
||||
(index - b) % a == 0
|
||||
// Is there a non-negative integer n such that An+B=index?
|
||||
match index.checked_sub(b) {
|
||||
None => false,
|
||||
Some(an) => match an.checked_div(a) {
|
||||
Some(n) => n >= 0 && a * n == an,
|
||||
None /* a == 0 */ => an == 0,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue