diff options
| author | Hisham <hisham@gobolinux.org> | 2016-10-28 11:58:04 -0200 |
|---|---|---|
| committer | Hisham <hisham@gobolinux.org> | 2016-10-28 11:58:04 -0200 |
| commit | 825f903a29df24b912e77e48d8b59e43e3a72029 (patch) | |
| tree | 5cc9180d281beb4e78535779849cd4e306d25b03 | |
| parent | 66cc4dfe45b4691a83b1b234bb626b60c16fd020 (diff) | |
| parent | afd9b2a4f2187b802f1febcff9b54073c6d8943d (diff) | |
| download | luarocks-825f903a29df24b912e77e48d8b59e43e3a72029.tar.gz luarocks-825f903a29df24b912e77e48d8b59e43e3a72029.tar.bz2 luarocks-825f903a29df24b912e77e48d8b59e43e3a72029.zip | |
Merge branch 'master' of https://github.com/keplerproject/luarocks
| -rw-r--r-- | spec/fs_spec.lua | 21 | ||||
| -rw-r--r-- | src/luarocks/fs/lua.lua | 11 | ||||
| -rw-r--r-- | src/luarocks/fs/unix.lua | 9 | ||||
| -rw-r--r-- | src/luarocks/fs/win32.lua | 30 |
4 files changed, 39 insertions, 32 deletions
diff --git a/spec/fs_spec.lua b/spec/fs_spec.lua new file mode 100644 index 00000000..c76f47a4 --- /dev/null +++ b/spec/fs_spec.lua | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | local test_env = require("test/test_environment") | ||
| 2 | |||
| 3 | test_env.unload_luarocks() | ||
| 4 | local fs = require("luarocks.fs") | ||
| 5 | local is_win = test_env.TEST_TARGET_OS == "windows" | ||
| 6 | |||
| 7 | describe("Luarocks fs test #whitebox #w_fs", function() | ||
| 8 | describe("fs.Q", function() | ||
| 9 | it("simple argument", function() | ||
| 10 | assert.are.same(is_win and '"foo"' or "'foo'", fs.Q("foo")) | ||
| 11 | end) | ||
| 12 | |||
| 13 | it("argument with quotes", function() | ||
| 14 | assert.are.same(is_win and [["it's \"quoting\""]] or [['it'\''s "quoting"']], fs.Q([[it's "quoting"]])) | ||
| 15 | end) | ||
| 16 | |||
| 17 | it("argument with special characters", function() | ||
| 18 | assert.are.same(is_win and [["\\"%" \\\\" \\\\\\"]] or [['\% \\" \\\']], fs.Q([[\% \\" \\\]])) | ||
| 19 | end) | ||
| 20 | end) | ||
| 21 | end) | ||
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index a31cbb4e..41711eab 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
| @@ -30,17 +30,6 @@ local dir_stack = {} | |||
| 30 | 30 | ||
| 31 | local dir_separator = "/" | 31 | local dir_separator = "/" |
| 32 | 32 | ||
| 33 | --- Quote argument for shell processing. | ||
| 34 | -- Adds single quotes and escapes. | ||
| 35 | -- @param arg string: Unquoted argument. | ||
| 36 | -- @return string: Quoted argument. | ||
| 37 | function fs_lua.Q(arg) | ||
| 38 | assert(type(arg) == "string") | ||
| 39 | |||
| 40 | -- FIXME Unix-specific | ||
| 41 | return "'" .. arg:gsub("'", "'\\''") .. "'" | ||
| 42 | end | ||
| 43 | |||
| 44 | --- Test is file/dir is writable. | 33 | --- Test is file/dir is writable. |
| 45 | -- Warning: testing if a file/dir is writable does not guarantee | 34 | -- Warning: testing if a file/dir is writable does not guarantee |
| 46 | -- that it will remain writable and therefore it is no replacement | 35 | -- that it will remain writable and therefore it is no replacement |
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 5c6b542c..e2bdc7b8 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua | |||
| @@ -22,6 +22,15 @@ function unix.quiet_stderr(cmd) | |||
| 22 | return cmd.." 2> /dev/null" | 22 | return cmd.." 2> /dev/null" |
| 23 | end | 23 | end |
| 24 | 24 | ||
| 25 | --- Quote argument for shell processing. | ||
| 26 | -- Adds single quotes and escapes. | ||
| 27 | -- @param arg string: Unquoted argument. | ||
| 28 | -- @return string: Quoted argument. | ||
| 29 | function unix.Q(arg) | ||
| 30 | assert(type(arg) == "string") | ||
| 31 | return "'" .. arg:gsub("'", "'\\''") .. "'" | ||
| 32 | end | ||
| 33 | |||
| 25 | --- Return an absolute pathname from a potentially relative one. | 34 | --- Return an absolute pathname from a potentially relative one. |
| 26 | -- @param pathname string: pathname to convert. | 35 | -- @param pathname string: pathname to convert. |
| 27 | -- @param relative_to string or nil: path to prepend when making | 36 | -- @param relative_to string or nil: path to prepend when making |
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 | ||
