summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorTim Ledbetter <timledbetter@gmail.com>2023-04-08 22:51:59 +0100
committerAndrew Kaster <andrewdkaster@gmail.com>2023-04-25 02:16:48 -0600
commit9d30eb4b34ddbd17d666a9ac50e654e484125970 (patch)
treef0620162bcb32c54692ddedffd4fd0f4fc05ac4a /Userland/Libraries
parent2618639bdb947a479d7fae49d8daa25946603ed5 (diff)
downloadserenity-9d30eb4b34ddbd17d666a9ac50e654e484125970.zip
LibManual: Allow paths that include subsections when creating PageNodes
Previously, attempting to open a man file within a subsection would fail.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibManual/Node.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/Userland/Libraries/LibManual/Node.cpp b/Userland/Libraries/LibManual/Node.cpp
index 4c89ff8a7a..e54fcc8595 100644
--- a/Userland/Libraries/LibManual/Node.cpp
+++ b/Userland/Libraries/LibManual/Node.cpp
@@ -32,16 +32,23 @@ ErrorOr<NonnullRefPtr<PageNode const>> Node::try_create_from_query(Vector<String
if (query_parameter_iterator.is_end()) {
// [/path/to/docs.md]
auto path_from_query = LexicalPath { first_query_parameter };
+ constexpr auto MARKDOWN_FILE_EXTENSION = "md"sv;
if (path_from_query.is_absolute()
&& path_from_query.is_child_of(manual_base_path)
- && path_from_query.extension() == "md"sv) {
- auto section_directory = path_from_query.parent();
- auto man_string_location = section_directory.basename().find("man"sv);
- if (!man_string_location.has_value())
+ && path_from_query.extension() == MARKDOWN_FILE_EXTENSION) {
+ // Parse the section number and page name from a directory string of the form:
+ // /usr/share/man/man[section_number]/[page_name].md
+ // The page_name includes any subsections.
+ auto const& section_directory = path_from_query.string();
+ auto section_name_start_index = manual_base_path.string().length() + 4;
+ auto section_name_end_index = section_directory.find('/', section_name_start_index);
+ if (!section_name_end_index.has_value())
return Error::from_string_literal("Page is inside invalid section");
- auto section_name = section_directory.basename().substring_view(man_string_location.value() + 3);
+ auto section_name = section_directory.substring_view(section_name_start_index, section_name_end_index.value() - section_name_start_index);
auto section = TRY(SectionNode::try_create_from_number(section_name));
- return try_make_ref_counted<PageNode>(section, TRY(String::from_utf8(path_from_query.title())));
+ auto page_name_end_index = section_directory.length() - section_name_end_index.value() - MARKDOWN_FILE_EXTENSION.length() - 1;
+ auto page_name = section_directory.substring_view(section_name_end_index.value(), page_name_end_index);
+ return try_make_ref_counted<PageNode>(section, TRY(String::from_utf8(page_name)));
}
// [page] (in any section)