mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
LibURL+LibWeb: Remove leading slash when converting url to path
...on Windows
This commit is contained in:
parent
5ff32fb090
commit
32ddeb82d6
Notes:
github-actions[bot]
2025-04-11 01:05:22 +00:00
Author: https://github.com/stasoid
Commit: 32ddeb82d6
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3569
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/R-Goc
Reviewed-by: https://github.com/shannonbooth ✅
5 changed files with 18 additions and 5 deletions
|
@ -246,6 +246,18 @@ String URL::serialize_path() const
|
|||
return output.to_string_without_validation();
|
||||
}
|
||||
|
||||
// This function is used whenever a path is needed to access the actual file on disk.
|
||||
// On Windows serialize_path can produce a path like /C:/path/to/tst.htm, so the leading slash needs to be removed to obtain a valid path.
|
||||
ByteString URL::file_path() const
|
||||
{
|
||||
ByteString path = percent_decode(serialize_path());
|
||||
#ifdef AK_OS_WINDOWS
|
||||
if (path.starts_with('/'))
|
||||
path = path.substring(1);
|
||||
#endif
|
||||
return path;
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#concept-url-serializer
|
||||
String URL::serialize(ExcludeFragment exclude_fragment) const
|
||||
{
|
||||
|
|
|
@ -122,6 +122,7 @@ public:
|
|||
}
|
||||
|
||||
String serialize_path() const;
|
||||
ByteString file_path() const;
|
||||
String serialize(ExcludeFragment = ExcludeFragment::No) const;
|
||||
ByteString serialize_for_display() const;
|
||||
ByteString to_byte_string() const { return serialize().to_byte_string(); }
|
||||
|
|
|
@ -45,7 +45,7 @@ ErrorOr<String> load_error_page(URL::URL const& url, StringView error_message)
|
|||
ErrorOr<String> load_file_directory_page(URL::URL const& url)
|
||||
{
|
||||
// Generate HTML contents entries table
|
||||
auto lexical_path = LexicalPath(URL::percent_decode(url.serialize_path()));
|
||||
auto lexical_path = LexicalPath(url.file_path());
|
||||
Core::DirIterator dt(lexical_path.string(), Core::DirIterator::Flags::SkipParentAndBaseDir);
|
||||
Vector<ByteString> names;
|
||||
while (dt.has_next())
|
||||
|
|
|
@ -102,7 +102,7 @@ void Resource::did_load(Badge<ResourceLoader>, ReadonlyBytes data, HTTP::HeaderM
|
|||
if (content_type_options.value_or("").equals_ignoring_ascii_case("nosniff"sv)) {
|
||||
m_mime_type = "text/plain";
|
||||
} else {
|
||||
m_mime_type = Core::guess_mime_type_based_on_filename(URL::percent_decode(url().serialize_path()));
|
||||
m_mime_type = Core::guess_mime_type_based_on_filename(url().file_path());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -321,7 +321,7 @@ void ResourceLoader::load(LoadRequest& request, GC::Root<SuccessCallback> succes
|
|||
}
|
||||
|
||||
auto data = resource.value()->data();
|
||||
auto response_headers = response_headers_for_file(URL::percent_decode(url.serialize_path()), resource.value()->modified_time());
|
||||
auto response_headers = response_headers_for_file(url.file_path(), resource.value()->modified_time());
|
||||
|
||||
// FIXME: Implement timing info for resource requests.
|
||||
Requests::RequestTimingInfo fixme_implement_timing_info {};
|
||||
|
@ -339,7 +339,7 @@ void ResourceLoader::load(LoadRequest& request, GC::Root<SuccessCallback> succes
|
|||
return;
|
||||
}
|
||||
|
||||
FileRequest file_request(URL::percent_decode(url.serialize_path()), [this, success_callback, error_callback, request, respond_directory_page](ErrorOr<i32> file_or_error) {
|
||||
FileRequest file_request(url.file_path(), [this, success_callback, error_callback, request, respond_directory_page](ErrorOr<i32> file_or_error) {
|
||||
--m_pending_loads;
|
||||
if (on_load_counter_change)
|
||||
on_load_counter_change();
|
||||
|
@ -387,7 +387,7 @@ void ResourceLoader::load(LoadRequest& request, GC::Root<SuccessCallback> succes
|
|||
}
|
||||
|
||||
auto data = maybe_data.release_value();
|
||||
auto response_headers = response_headers_for_file(URL::percent_decode(request.url().serialize_path()), st_or_error.value().st_mtime);
|
||||
auto response_headers = response_headers_for_file(request.url().file_path(), st_or_error.value().st_mtime);
|
||||
|
||||
// FIXME: Implement timing info for file requests.
|
||||
Requests::RequestTimingInfo fixme_implement_timing_info {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue