aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Melnichenko <mpeterval@gmail.com>2016-10-28 14:09:20 +0300
committerPeter Melnichenko <mpeterval@gmail.com>2016-10-28 14:28:52 +0300
commitafd9b2a4f2187b802f1febcff9b54073c6d8943d (patch)
tree8a1d7fd579f64bb65612fb77d77474cb845bab42 /src
parent7f67011db75e671068b7f02d5489491f512bf816 (diff)
downloadluarocks-afd9b2a4f2187b802f1febcff9b54073c6d8943d.tar.gz
luarocks-afd9b2a4f2187b802f1febcff9b54073c6d8943d.tar.bz2
luarocks-afd9b2a4f2187b802f1febcff9b54073c6d8943d.zip
Refactor windows argument quoting functions
Use string replacements instead of functions in calls to gsub.
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/fs/win32.lua30
1 files changed, 9 insertions, 21 deletions
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua
index c99cc895..14804713 100644
--- a/src/luarocks/fs/win32.lua
+++ b/src/luarocks/fs/win32.lua
@@ -35,19 +35,6 @@ end
35 35
36local drive_letter = "[%.a-zA-Z]?:?[\\/]" 36local drive_letter = "[%.a-zA-Z]?:?[\\/]"
37 37
38local win_escape_chars = {
39 ["%"] = "%%",
40 ['"'] = '\\"',
41}
42
43local function q_escaper(bs, q)
44 return ("\\"):rep(2*#bs-1) .. (q or "\\")
45end
46
47local function p_escaper(bs)
48 return bs .. bs .. '"%"'
49end
50
51--- Quote argument for shell processing. Fixes paths on Windows. 38--- Quote argument for shell processing. Fixes paths on Windows.
52-- Adds double quotes and escapes. 39-- Adds double quotes and escapes.
53-- @param arg string: Unquoted argument. 40-- @param arg string: Unquoted argument.
@@ -61,11 +48,11 @@ function win32.Q(arg)
61 if arg == "\\" then 48 if arg == "\\" then
62 return '\\' -- CHDIR needs special handling for root dir 49 return '\\' -- CHDIR needs special handling for root dir
63 end 50 end
64 -- URLs and anything else 51 -- URLs and anything else
65 arg = arg:gsub('(\\+)(")', q_escaper) 52 arg = arg:gsub('\\(\\*)"', '\\%1%1"')
66 arg = arg:gsub('(\\+)$', q_escaper) 53 arg = arg:gsub('\\+$', '%0%0')
67 arg = arg:gsub('"', win_escape_chars) 54 arg = arg:gsub('"', '\\"')
68 arg = arg:gsub('(\\*)%%', p_escaper) 55 arg = arg:gsub('(\\*)%%', '%1%1"%%"')
69 return '"' .. arg .. '"' 56 return '"' .. arg .. '"'
70end 57end
71 58
@@ -83,9 +70,10 @@ function win32.Qb(arg)
83 return '\\' -- CHDIR needs special handling for root dir 70 return '\\' -- CHDIR needs special handling for root dir
84 end 71 end
85 -- URLs and anything else 72 -- URLs and anything else
86 arg = arg:gsub('(\\+)(")', q_escaper) 73 arg = arg:gsub('\\(\\*)"', '\\%1%1"')
87 arg = arg:gsub('(\\+)$', q_escaper) 74 arg = arg:gsub('\\+$', '%0%0')
88 arg = arg:gsub('[%%"]', win_escape_chars) 75 arg = arg:gsub('"', '\\"')
76 arg = arg:gsub('%%', '%%%%')
89 return '"' .. arg .. '"' 77 return '"' .. arg .. '"'
90end 78end
91 79