mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 01:32:14 -05: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
1 changed files with 14 additions and 10 deletions
|
@ -28,6 +28,7 @@
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/EventLoop.h>
|
#include <LibCore/EventLoop.h>
|
||||||
|
#include <LibCore/File.h>
|
||||||
#include <LibDesktop/Launcher.h>
|
#include <LibDesktop/Launcher.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -42,17 +43,20 @@ int main(int argc, char* argv[])
|
||||||
bool all_ok = true;
|
bool all_ok = true;
|
||||||
|
|
||||||
for (auto& url_or_path : urls_or_paths) {
|
for (auto& url_or_path : urls_or_paths) {
|
||||||
URL url = URL::create_with_url_or_path(url_or_path);
|
String path;
|
||||||
if (url.protocol() == "file" && !url.path().starts_with('/')) {
|
auto realpath_errno = 0;
|
||||||
if (auto* path = realpath(url.path().characters(), nullptr)) {
|
if (path = Core::File::real_path_for(url_or_path); path.is_null()) {
|
||||||
url.set_path(path);
|
realpath_errno = errno; // This *should* be preserved from Core::File::real_path_for().
|
||||||
free(path);
|
path = url_or_path;
|
||||||
} else {
|
|
||||||
fprintf(stderr, "Failed to open '%s': %s\n", url.path().characters(), strerror(errno));
|
|
||||||
all_ok = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)) {
|
if (!Desktop::Launcher::open(url)) {
|
||||||
fprintf(stderr, "Failed to open '%s'\n", url.path().characters());
|
fprintf(stderr, "Failed to open '%s'\n", url.path().characters());
|
||||||
all_ok = false;
|
all_ok = false;
|
||||||
|
|
Loading…
Reference in a new issue