mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:17:35 +00:00
LibManual: Ensure page exists when opening a help URL
Previously, Help could crash when attempting to open a help URL for a page that doesn't exist.
This commit is contained in:
parent
d6b786b3fe
commit
6ab13489ee
1 changed files with 9 additions and 1 deletions
|
@ -89,17 +89,25 @@ ErrorOr<NonnullRefPtr<Node const>> Node::try_find_from_help_url(URL const& url)
|
|||
return Error::from_string_view("Section number out of bounds"sv);
|
||||
|
||||
NonnullRefPtr<Node const> current_node = sections[section_number - 1];
|
||||
|
||||
bool child_node_found;
|
||||
for (size_t i = 1; i < url.path_segment_count(); i++) {
|
||||
child_node_found = false;
|
||||
auto children = TRY(current_node->children());
|
||||
for (auto const& child : children) {
|
||||
if (TRY(child->name()) == url.path_segment_at_index(i).view()) {
|
||||
child_node_found = true;
|
||||
current_node = child;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!child_node_found)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!child_node_found)
|
||||
return Error::from_string_view("Page not found"sv);
|
||||
|
||||
return current_node;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue