summary refs log tree commit diff stats
path: root/lib/pure/os.nim
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-08-12 07:50:08 -0700
committerGitHub <noreply@github.com>2021-08-12 16:50:08 +0200
commit5c1304a4181596e764b05679cd8a0044ab3398dd (patch)
treea68e7a65e1725012e38d8a0acea9857742f0a5b2 /lib/pure/os.nim
parent018465a2345b2d11f7d1d711010d97e636af98d0 (diff)
downloadNim-5c1304a4181596e764b05679cd8a0044ab3398dd.tar.gz
fix #18670 quoteShellCommand, quoteShell, quoteShellWindows on windows (#18671)
Diffstat (limited to 'lib/pure/os.nim')
-rw-r--r--lib/pure/os.nim11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index fd618e93c..cfdacdb3c 100644
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -1045,15 +1045,12 @@ proc expandTilde*(path: string): string {.
     # TODO: handle `~bob` and `~bob/` which means home of bob
     result = path
 
-# TODO: consider whether quoteShellPosix, quoteShellWindows, quoteShell, quoteShellCommand
-# belong in `strutils` instead; they are not specific to paths
 proc quoteShellWindows*(s: string): string {.noSideEffect, rtl, extern: "nosp$1".} =
   ## Quote `s`, so it can be safely passed to Windows API.
   ##
   ## Based on Python's `subprocess.list2cmdline`.
   ## See `this link <http://msdn.microsoft.com/en-us/library/17w5ykft.aspx>`_
   ## for more details.
-
   let needQuote = {' ', '\t'} in s or s.len == 0
   result = ""
   var backslashBuff = ""
@@ -1064,8 +1061,8 @@ proc quoteShellWindows*(s: string): string {.noSideEffect, rtl, extern: "nosp$1"
     if c == '\\':
       backslashBuff.add(c)
     elif c == '\"':
-      result.add(backslashBuff)
-      result.add(backslashBuff)
+      for i in 0..<backslashBuff.len*2:
+        result.add('\\')
       backslashBuff.setLen(0)
       result.add("\\\"")
     else:
@@ -1074,9 +1071,13 @@ proc quoteShellWindows*(s: string): string {.noSideEffect, rtl, extern: "nosp$1"
         backslashBuff.setLen(0)
       result.add(c)
 
+  if backslashBuff.len > 0:
+    result.add(backslashBuff)
   if needQuote:
+    result.add(backslashBuff)
     result.add("\"")
 
+
 proc quoteShellPosix*(s: string): string {.noSideEffect, rtl, extern: "nosp$1".} =
   ## Quote ``s``, so it can be safely passed to POSIX shell.
   const safeUnixChars = {'%', '+', '-', '.', '/', '_', ':', '=', '@',
053309e60aee1eda594a4817ac8ac2fb8c18fb04'>053309e60 ^
5b28d0820 ^
053309e60 ^

105a0616a ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39