mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 11:47:34 +00:00
AK+Everywhere: Change URL::path() to serialize_path()
This now defaults to serializing the path with percent decoded segments (which is what all callers expect), but has an option not to. This fixes `file://` URLs with spaces in their paths. The name has been changed to serialize_path() path to make it more clear that this method will generate a new string each call (except for the cannot_be_a_base_url() case). A few callers have then been updated to avoid repeatedly calling this function.
This commit is contained in:
parent
5acd40c525
commit
35612c6a7f
42 changed files with 131 additions and 123 deletions
|
@ -192,29 +192,30 @@ RecursionDecision MarkdownLinkage::visit(Markdown::Text::LinkNode const& link_no
|
|||
m_has_invalid_link = true;
|
||||
return RecursionDecision::Recurse;
|
||||
}
|
||||
if (url.paths().size() < 2) {
|
||||
if (url.path_segment_count() < 2) {
|
||||
warnln("help://man URL is missing section or page: {}", href);
|
||||
m_has_invalid_link = true;
|
||||
return RecursionDecision::Recurse;
|
||||
}
|
||||
|
||||
// Remove leading '/' from the path.
|
||||
auto file = DeprecatedString::formatted("{}/Base/usr/share/man/man{}.md", m_serenity_source_directory, url.path().substring(1));
|
||||
auto file = DeprecatedString::formatted("{}/Base/usr/share/man/man{}.md", m_serenity_source_directory, url.serialize_path().substring(1));
|
||||
|
||||
m_file_links.append({ file, DeprecatedString(), StringCollector::from(*link_node.text) });
|
||||
return RecursionDecision::Recurse;
|
||||
}
|
||||
if (url.scheme() == "file") {
|
||||
if (url.path().contains("man"sv) && url.path().ends_with(".md"sv)) {
|
||||
auto file_path = url.serialize_path();
|
||||
if (file_path.contains("man"sv) && file_path.ends_with(".md"sv)) {
|
||||
warnln("Inter-manpage link without the help:// scheme: {}\nPlease use help URLs of the form 'help://man/<section>/<subsection...>/<page>'", href);
|
||||
m_has_invalid_link = true;
|
||||
return RecursionDecision::Recurse;
|
||||
}
|
||||
// TODO: Check more possible links other than icons.
|
||||
if (url.path().starts_with("/res/icons/"sv)) {
|
||||
auto file = DeprecatedString::formatted("{}/Base{}", m_serenity_source_directory, url.path());
|
||||
if (file_path.starts_with("/res/icons/"sv)) {
|
||||
auto file = DeprecatedString::formatted("{}/Base{}", m_serenity_source_directory, file_path);
|
||||
m_file_links.append({ file, DeprecatedString(), StringCollector::from(*link_node.text) });
|
||||
} else if (url.path().starts_with("/bin"sv)) {
|
||||
} else if (file_path.starts_with("/bin"sv)) {
|
||||
StringBuilder builder;
|
||||
link_node.text->render_to_html(builder);
|
||||
auto link_text = builder.string_view();
|
||||
|
|
|
@ -324,7 +324,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
}
|
||||
|
||||
if (output_name.is_empty())
|
||||
output_name = url.path();
|
||||
output_name = url.serialize_path();
|
||||
|
||||
LexicalPath path { output_name };
|
||||
output_name = path.basename();
|
||||
|
|
|
@ -371,7 +371,7 @@ static auto parse(StringView contents)
|
|||
if (url.scheme() != "file")
|
||||
return Error::from_string_literal("NYI: Nonlocal entity");
|
||||
|
||||
auto file = TRY(Core::File::open(url.path(), Core::File::OpenMode::Read));
|
||||
auto file = TRY(Core::File::open(url.serialize_path(), Core::File::OpenMode::Read));
|
||||
return DeprecatedString::copy(TRY(file->read_until_eof()));
|
||||
},
|
||||
},
|
||||
|
@ -440,28 +440,29 @@ static void do_run_tests(XML::Document& document)
|
|||
continue;
|
||||
}
|
||||
|
||||
auto file_result = Core::File::open(url.path(), Core::File::OpenMode::Read);
|
||||
auto file_path = url.serialize_path();
|
||||
auto file_result = Core::File::open(file_path, Core::File::OpenMode::Read);
|
||||
if (file_result.is_error()) {
|
||||
warnln("Read error for {}: {}", url.path(), file_result.error());
|
||||
s_test_results.set(url.path(), TestResult::RunnerFailed);
|
||||
warnln("Read error for {}: {}", file_path, file_result.error());
|
||||
s_test_results.set(file_path, TestResult::RunnerFailed);
|
||||
continue;
|
||||
}
|
||||
|
||||
warnln("Running test {}", url.path());
|
||||
warnln("Running test {}", file_path);
|
||||
|
||||
auto contents = file_result.value()->read_until_eof();
|
||||
if (contents.is_error()) {
|
||||
warnln("Read error for {}: {}", url.path(), contents.error());
|
||||
s_test_results.set(url.path(), TestResult::RunnerFailed);
|
||||
warnln("Read error for {}: {}", file_path, contents.error());
|
||||
s_test_results.set(file_path, TestResult::RunnerFailed);
|
||||
continue;
|
||||
}
|
||||
auto parser = parse(contents.value());
|
||||
auto doc_or_error = parser.parse();
|
||||
if (doc_or_error.is_error()) {
|
||||
if (type == "invalid" || type == "error" || type == "not-wf")
|
||||
s_test_results.set(url.path(), TestResult::Passed);
|
||||
s_test_results.set(file_path, TestResult::Passed);
|
||||
else
|
||||
s_test_results.set(url.path(), TestResult::Failed);
|
||||
s_test_results.set(file_path, TestResult::Failed);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -471,33 +472,33 @@ static void do_run_tests(XML::Document& document)
|
|||
auto file_result = Core::File::open(out_path, Core::File::OpenMode::Read);
|
||||
if (file_result.is_error()) {
|
||||
warnln("Read error for {}: {}", out_path, file_result.error());
|
||||
s_test_results.set(url.path(), TestResult::RunnerFailed);
|
||||
s_test_results.set(file_path, TestResult::RunnerFailed);
|
||||
continue;
|
||||
}
|
||||
auto contents = file_result.value()->read_until_eof();
|
||||
if (contents.is_error()) {
|
||||
warnln("Read error for {}: {}", out_path, contents.error());
|
||||
s_test_results.set(url.path(), TestResult::RunnerFailed);
|
||||
s_test_results.set(file_path, TestResult::RunnerFailed);
|
||||
continue;
|
||||
}
|
||||
auto parser = parse(contents.value());
|
||||
auto out_doc_or_error = parser.parse();
|
||||
if (out_doc_or_error.is_error()) {
|
||||
warnln("Parse error for {}: {}", out_path, out_doc_or_error.error());
|
||||
s_test_results.set(url.path(), TestResult::RunnerFailed);
|
||||
s_test_results.set(file_path, TestResult::RunnerFailed);
|
||||
continue;
|
||||
}
|
||||
auto out_doc = out_doc_or_error.release_value();
|
||||
if (out_doc.root() != doc_or_error.value().root()) {
|
||||
s_test_results.set(url.path(), TestResult::Failed);
|
||||
s_test_results.set(file_path, TestResult::Failed);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == "invalid" || type == "error" || type == "not-wf")
|
||||
s_test_results.set(url.path(), TestResult::Failed);
|
||||
s_test_results.set(file_path, TestResult::Failed);
|
||||
else
|
||||
s_test_results.set(url.path(), TestResult::Passed);
|
||||
s_test_results.set(file_path, TestResult::Passed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue