diff options
| author | Peter Melnichenko <mpeterval@gmail.com> | 2016-10-28 14:09:20 +0300 |
|---|---|---|
| committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-10-28 14:28:52 +0300 |
| commit | afd9b2a4f2187b802f1febcff9b54073c6d8943d (patch) | |
| tree | 8a1d7fd579f64bb65612fb77d77474cb845bab42 | |
| parent | 7f67011db75e671068b7f02d5489491f512bf816 (diff) | |
| download | luarocks-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.
| -rw-r--r-- | src/luarocks/fs/win32.lua | 30 |
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 | ||
| 36 | local drive_letter = "[%.a-zA-Z]?:?[\\/]" | 36 | local drive_letter = "[%.a-zA-Z]?:?[\\/]" |
| 37 | 37 | ||
| 38 | local win_escape_chars = { | ||
| 39 | ["%"] = "%%", | ||
| 40 | ['"'] = '\\"', | ||
| 41 | } | ||
| 42 | |||
| 43 | local function q_escaper(bs, q) | ||
| 44 | return ("\\"):rep(2*#bs-1) .. (q or "\\") | ||
| 45 | end | ||
| 46 | |||
| 47 | local function p_escaper(bs) | ||
| 48 | return bs .. bs .. '"%"' | ||
| 49 | end | ||
| 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 .. '"' |
| 70 | end | 57 | end |
| 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 .. '"' |
| 90 | end | 78 | end |
| 91 | 79 | ||
