summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibManual
diff options
context:
space:
mode:
authorTim Ledbetter <timledbetter@gmail.com>2023-04-25 17:34:08 +0100
committerAndrew Kaster <andrewdkaster@gmail.com>2023-05-08 21:03:19 -0600
commit6ab13489eed93f75643caa9c986ef44078a46f48 (patch)
treeaf97057e84eaf265e666b1772aa4fceaca918b54 /Userland/Libraries/LibManual
parentd6b786b3fe76b9e256693205347c45472472782b (diff)
downloadserenity-6ab13489eed93f75643caa9c986ef44078a46f48.zip
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.
Diffstat (limited to 'Userland/Libraries/LibManual')
-rw-r--r--Userland/Libraries/LibManual/Node.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/Userland/Libraries/LibManual/Node.cpp b/Userland/Libraries/LibManual/Node.cpp
index e54fcc8595..dc6871d07f 100644
--- a/Userland/Libraries/LibManual/Node.cpp
+++ b/Userland/Libraries/LibManual/Node.cpp
@@ -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;
}