LibURL+LibWeb: Remove leading slash when converting url to path

...on Windows
This commit is contained in:
stasoid 2025-02-14 15:31:43 +05:00 committed by Andrew Kaster
parent 5ff32fb090
commit 32ddeb82d6
Notes: github-actions[bot] 2025-04-11 01:05:22 +00:00
5 changed files with 18 additions and 5 deletions

View file

@ -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
{