From 8630a263b6c5f86d57eb0f3a49ddce163c8378c1 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 28 Oct 2016 14:23:04 +0300 Subject: Add a few tests for fs.Q --- spec/fs_spec.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 spec/fs_spec.lua 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 @@ +local test_env = require("test/test_environment") + +test_env.unload_luarocks() +local fs = require("luarocks.fs") +local is_win = test_env.TEST_TARGET_OS == "windows" + +describe("Luarocks fs test #whitebox #w_fs", function() + describe("fs.Q", function() + it("simple argument", function() + assert.are.same(is_win and '"foo"' or "'foo'", fs.Q("foo")) + end) + + it("argument with quotes", function() + assert.are.same(is_win and [["it's \"quoting\""]] or [['it'\''s "quoting"']], fs.Q([[it's "quoting"]])) + end) + + it("argument with special characters", function() + assert.are.same(is_win and [["\\"%" \\\\" \\\\\\"]] or [['\% \\" \\\']], fs.Q([[\% \\" \\\]])) + end) + end) +end) -- cgit v1.2.3-55-g6feb From 7f67011db75e671068b7f02d5489491f512bf816 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 28 Oct 2016 14:27:51 +0300 Subject: Move Unix-specific fs.Q implementation into luarocks.fs.unix --- src/luarocks/fs/lua.lua | 11 ----------- src/luarocks/fs/unix.lua | 9 +++++++++ 2 files changed, 9 insertions(+), 11 deletions(-) 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 = {} local dir_separator = "/" ---- Quote argument for shell processing. --- Adds single quotes and escapes. --- @param arg string: Unquoted argument. --- @return string: Quoted argument. -function fs_lua.Q(arg) - assert(type(arg) == "string") - - -- FIXME Unix-specific - return "'" .. arg:gsub("'", "'\\''") .. "'" -end - --- Test is file/dir is writable. -- Warning: testing if a file/dir is writable does not guarantee -- 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) return cmd.." 2> /dev/null" end +--- Quote argument for shell processing. +-- Adds single quotes and escapes. +-- @param arg string: Unquoted argument. +-- @return string: Quoted argument. +function unix.Q(arg) + assert(type(arg) == "string") + return "'" .. arg:gsub("'", "'\\''") .. "'" +end + --- Return an absolute pathname from a potentially relative one. -- @param pathname string: pathname to convert. -- @param relative_to string or nil: path to prepend when making -- cgit v1.2.3-55-g6feb From afd9b2a4f2187b802f1febcff9b54073c6d8943d Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 28 Oct 2016 14:09:20 +0300 Subject: Refactor windows argument quoting functions Use string replacements instead of functions in calls to gsub. --- src/luarocks/fs/win32.lua | 30 +++++++++--------------------- 1 file 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 local drive_letter = "[%.a-zA-Z]?:?[\\/]" -local win_escape_chars = { - ["%"] = "%%", - ['"'] = '\\"', -} - -local function q_escaper(bs, q) - return ("\\"):rep(2*#bs-1) .. (q or "\\") -end - -local function p_escaper(bs) - return bs .. bs .. '"%"' -end - --- Quote argument for shell processing. Fixes paths on Windows. -- Adds double quotes and escapes. -- @param arg string: Unquoted argument. @@ -61,11 +48,11 @@ function win32.Q(arg) if arg == "\\" then return '\\' -- CHDIR needs special handling for root dir end - -- URLs and anything else - arg = arg:gsub('(\\+)(")', q_escaper) - arg = arg:gsub('(\\+)$', q_escaper) - arg = arg:gsub('"', win_escape_chars) - arg = arg:gsub('(\\*)%%', p_escaper) + -- URLs and anything else + arg = arg:gsub('\\(\\*)"', '\\%1%1"') + arg = arg:gsub('\\+$', '%0%0') + arg = arg:gsub('"', '\\"') + arg = arg:gsub('(\\*)%%', '%1%1"%%"') return '"' .. arg .. '"' end @@ -83,9 +70,10 @@ function win32.Qb(arg) return '\\' -- CHDIR needs special handling for root dir end -- URLs and anything else - arg = arg:gsub('(\\+)(")', q_escaper) - arg = arg:gsub('(\\+)$', q_escaper) - arg = arg:gsub('[%%"]', win_escape_chars) + arg = arg:gsub('\\(\\*)"', '\\%1%1"') + arg = arg:gsub('\\+$', '%0%0') + arg = arg:gsub('"', '\\"') + arg = arg:gsub('%%', '%%%%') return '"' .. arg .. '"' end -- cgit v1.2.3-55-g6feb From 66cc4dfe45b4691a83b1b234bb626b60c16fd020 Mon Sep 17 00:00:00 2001 From: Hisham Date: Fri, 28 Oct 2016 11:53:07 -0200 Subject: Prefer versioned Lua interpreter if it exists. This avoids in practice a problem that occurs in this scenario: 1. user installs Lua 5.1, gets lua and lua5.1 binaries 2. user installs LuaRocks, it detects and uses lua 3. user installs Lua 5.2, gets lua and lua5.2 binaries (lua is replaced) 4. user installs LuaRocks with --lua-version=5.2, it detects and uses lua 5. luarocks-5.1 now uses lua, which is Lua 5.2, rockspecs get passed the wrong value of $(LUA) --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index ae2696d2..ab629f98 100755 --- a/configure +++ b/configure @@ -292,7 +292,7 @@ then else suffixes="5.3 53 -5.3 -53 5.2 52 -5.2 -52 5.1 51 -5.1 -51" fi - for suffix in "" `echo $suffixes` + for suffix in `echo $suffixes` "" do search_interpreter "$suffix" && { lua_interp_found=yes -- cgit v1.2.3-55-g6feb