From f9a24099c30c879a7d686fa5ea3f86ed2ab489b4 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sun, 13 Oct 2013 22:40:33 -0300 Subject: Escape doublebrackets in paths that go to wrappers. --- src/luarocks/fs/unix.lua | 2 ++ src/luarocks/fs/win32.lua | 3 +++ src/luarocks/util.lua | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 5b9a11b5..e154ef45 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua @@ -54,6 +54,8 @@ function wrap_script(file, dest, name, version) local base = dir.base_name(file) local wrapname = fs.is_dir(dest) and dest.."/"..base or dest local lpath, lcpath = cfg.package_paths() + lpath = util.escape_doublebrackets(lpath) + lcpath = util.escape_doublebrackets(lcpath) local wrapper = io.open(wrapname, "w") if not wrapper then return nil, "Could not open "..wrapname.." for writing." diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index 8f14239d..ba3ba2b3 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua @@ -7,6 +7,7 @@ local fs = require("luarocks.fs") local cfg = require("luarocks.cfg") local dir = require("luarocks.dir") +local util = require("luarocks.util") --- Annotate command string for quiet execution. -- @param cmd string: A command-line string. @@ -64,6 +65,8 @@ function wrap_script(file, dest, name, version) local wrapname = fs.is_dir(dest) and dest.."/"..base or dest wrapname = wrapname..".bat" local lpath, lcpath = cfg.package_paths() + lpath = util.escape_doublebrackets(lpath) + lcpath = util.escape_doublebrackets(lcpath) local wrapper = io.open(wrapname, "w") if not wrapper then return nil, "Could not open "..wrapname.." for writing." diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index e3260359..cfcd2013 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -511,3 +511,7 @@ function array_contains(tbl, value) end return false end + +function escape_doublebrackets(s) + return s:gsub("(([%[%]])%2)","]]..'%1'..[[") +end \ No newline at end of file -- cgit v1.2.3-55-g6feb