fixed incorrect backslashes escaping outside of tokens

This commit is contained in:
Damien Courtois 2015-07-07 14:43:31 +02:00
parent f5d7ef1a5b
commit b228a68919
2 changed files with 12 additions and 3 deletions

View File

@ -110,7 +110,7 @@
local count
repeat
value, count = value:gsub("%%{(.-)}", function(token)
local result, err = expandtoken(token, environ)
local result, err = expandtoken(token:gsub("\\", "\\\\"), environ)
if not result then
error(err, 0)
end
@ -139,8 +139,7 @@
end
return value
else
-- escape backslashes: they will break loadstring
return expandvalue(value:gsub("\\", "\\\\"))
return expandvalue(value)
end
end

View File

@ -129,3 +129,13 @@
x = detoken.expand("%{foo:gsub('/', '\\')}", environ)
test.isequal("some\\path", x)
end
--
-- Escapes backslashes correctly, but not outside tokens.
--
function suite.escapesBackslashes2()
environ.foo = "some/path"
x = detoken.expand("%{foo:gsub('/', '\\')}\\already\\escaped", environ)
test.isequal("some\\path\\already\\escaped", x)
end