diff options
Diffstat (limited to 'src/zen/cmds/ui_cmd.cpp')
| -rw-r--r-- | src/zen/cmds/ui_cmd.cpp | 39 |
1 files changed, 3 insertions, 36 deletions
diff --git a/src/zen/cmds/ui_cmd.cpp b/src/zen/cmds/ui_cmd.cpp index 28ab6c45c..3d3021857 100644 --- a/src/zen/cmds/ui_cmd.cpp +++ b/src/zen/cmds/ui_cmd.cpp @@ -2,6 +2,8 @@ #include "ui_cmd.h" +#include "browser_launcher.h" + #include <zencore/except_fmt.h> #include <zencore/fmtutils.h> #include <zencore/logging.h> @@ -9,11 +11,6 @@ #include <zenutil/consoletui.h> #include <zenutil/zenserverprocess.h> -#if ZEN_PLATFORM_WINDOWS -# include <zencore/windows.h> -# include <shellapi.h> -#endif - namespace zen { namespace { @@ -83,40 +80,10 @@ UiCommand::OpenBrowser(std::string_view HostName) } } - bool Success = false; - ExtendableStringBuilder<256> FullUrl; FullUrl << HostName << m_DashboardPath; -#if ZEN_PLATFORM_WINDOWS - HINSTANCE Result = ShellExecuteA(nullptr, "open", FullUrl.c_str(), nullptr, nullptr, SW_SHOWNORMAL); - Success = reinterpret_cast<intptr_t>(Result) > 32; -#else - // Validate URL doesn't contain shell metacharacters that could lead to command injection - std::string_view FullUrlView = FullUrl; - constexpr std::string_view DangerousChars = ";|&$`\\\"'<>(){}[]!#*?~\n\r"; - if (FullUrlView.find_first_of(DangerousChars) != std::string_view::npos) - { - throw OptionParseException(fmt::format("URL contains invalid characters: '{}'", FullUrl), m_Options.help()); - } - -# if ZEN_PLATFORM_MAC - std::string Command = fmt::format("open \"{}\"", FullUrl); -# elif ZEN_PLATFORM_LINUX - std::string Command = fmt::format("xdg-open \"{}\"", FullUrl); -# else - ZEN_NOT_IMPLEMENTED("Browser launching not implemented on this platform"); -# endif - - Success = system(Command.c_str()) == 0; -#endif - - if (!Success) - { - throw zen::runtime_error("Failed to launch browser for '{}'", FullUrl); - } - - ZEN_CONSOLE("Web browser launched for '{}' successfully", FullUrl); + LaunchBrowser(std::string_view(FullUrl)); } void |