1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07: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:
Tim Ledbetter 2023-04-25 17:34:08 +01:00 committed by Andrew Kaster
parent d6b786b3fe
commit 6ab13489ee

View file

@ -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;
}