Skip to content

Commit

Permalink
enforce browsers.nim only handles URLs [backport] (nim-lang#15045)
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq authored and mildred committed Jan 11, 2021
1 parent 7b63b1c commit dc632ac
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/pure/browsers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import strutils

when defined(windows):
import winlean
from os import absolutePath
else:
import os, osproc

Expand All @@ -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:
Expand Down

0 comments on commit dc632ac

Please sign in to comment.