mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02:00
LibWeb: Fix off-by-one in Navigation::can_go_forward()
The getter compares the current entry index against the entry list's size, but valid indices are in the range [0, size - 1]. An index equal to size is a past-the-end state that never occurs in practice, so the function always returns true for any valid index. This means it reports forward navigation is possible even when the current entry is the last one in the list, where forward() immediately throws an InvalidStateError. The symmetric can_go_back() correctly checks against index 0, and forward() correctly checks against size - 1. This brings can_go_forward() in line with both.
This commit is contained in:
committed by
Tim Flynn
parent
9e8e568b43
commit
49d24f1867
Notes:
github-actions[bot]
2026-02-13 14:39:46 +00:00
Author: https://github.com/Praise-Garfield Commit: https://github.com/LadybirdBrowser/ladybird/commit/49d24f1867f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7919 Reviewed-by: https://github.com/trflynn89
@@ -183,9 +183,9 @@ bool Navigation::can_go_forward() const
|
||||
// 2. Assert: navigation's current entry index is not −1.
|
||||
VERIFY(m_current_entry_index != -1);
|
||||
|
||||
// 3. If this's current entry index is equal to this's entry list's size, then return false.
|
||||
// 3. If this's current entry index is equal to this's entry list's size − 1, then return false.
|
||||
// 4. Return true.
|
||||
return (m_current_entry_index != static_cast<i64>(m_entry_list.size()));
|
||||
return (m_current_entry_index != static_cast<i64>(m_entry_list.size() - 1));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#history-handling-behavior
|
||||
|
||||
Reference in New Issue
Block a user