From 925dd92e07bd8b031c9f237ceb9e352c34a97d64 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 23 Jul 2020 11:03:39 +0200 Subject: [PATCH] enforce browsers.nim only handles URLs [backport] (#15045) --- lib/pure/browsers.nim | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/pure/browsers.nim b/lib/pure/browsers.nim index 2dc14b8955255..9b3b67104b2bd 100644 --- a/lib/pure/browsers.nim +++ b/lib/pure/browsers.nim @@ -18,6 +18,7 @@ import strutils when defined(windows): import winlean + from os import absolutePath else: import os, osproc @@ -26,16 +27,21 @@ const osOpenCmd* = ## Alias for the operating system specific *"open"* command, ## ``"open"`` on OSX, MacOS and Windows, ``"xdg-open"`` on Linux, BSD, etc. +proc prepare(s: string): string = + if s.contains("://"): + result = s + else: + result = "file://" & absolutePath(s) -template openDefaultBrowserImpl(url: string) = +proc openDefaultBrowserImpl(url: string) = when defined(windows): var o = newWideCString(osOpenCmd) - var u = newWideCString(url) + var u = newWideCString(prepare url) discard shellExecuteW(0'i32, o, u, nil, nil, SW_SHOWNORMAL) elif defined(macosx): - discard execShellCmd(osOpenCmd & " " & quoteShell(url)) + discard execShellCmd(osOpenCmd & " " & quoteShell(prepare url)) else: - var u = quoteShell(url) + var u = quoteShell(prepare url) if execShellCmd(osOpenCmd & " " & u) == 0: return for b in getEnv("BROWSER").string.split(PathSep): try: