mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 21:54:40 +03:00
open: Resolve the realpath before passing it to URL()
...which runs it through LexicalPath. Fixes #3016.
This commit is contained in:
parent
62ec42c112
commit
7ebba7bf3c
Notes:
sideshowbarker
2024-07-19 04:09:07 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/7ebba7bf3c8 Pull-request: https://github.com/SerenityOS/serenity/pull/3043 Issue: https://github.com/SerenityOS/serenity/issues/3016
@ -28,6 +28,7 @@
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibDesktop/Launcher.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -42,17 +43,20 @@ int main(int argc, char* argv[])
|
||||
bool all_ok = true;
|
||||
|
||||
for (auto& url_or_path : urls_or_paths) {
|
||||
URL url = URL::create_with_url_or_path(url_or_path);
|
||||
if (url.protocol() == "file" && !url.path().starts_with('/')) {
|
||||
if (auto* path = realpath(url.path().characters(), nullptr)) {
|
||||
url.set_path(path);
|
||||
free(path);
|
||||
} else {
|
||||
fprintf(stderr, "Failed to open '%s': %s\n", url.path().characters(), strerror(errno));
|
||||
all_ok = false;
|
||||
continue;
|
||||
}
|
||||
String path;
|
||||
auto realpath_errno = 0;
|
||||
if (path = Core::File::real_path_for(url_or_path); path.is_null()) {
|
||||
realpath_errno = errno; // This *should* be preserved from Core::File::real_path_for().
|
||||
path = url_or_path;
|
||||
}
|
||||
|
||||
URL url = URL::create_with_url_or_path(path);
|
||||
if (url.protocol() == "file" && realpath_errno) {
|
||||
fprintf(stderr, "Failed to open '%s': %s\n", url.path().characters(), strerror(realpath_errno));
|
||||
all_ok = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!Desktop::Launcher::open(url)) {
|
||||
fprintf(stderr, "Failed to open '%s'\n", url.path().characters());
|
||||
all_ok = false;
|
||||
|
Loading…
Reference in New Issue
Block a user