diff --git a/src/base/detoken.lua b/src/base/detoken.lua index a89d903a..17a89448 100644 --- a/src/base/detoken.lua +++ b/src/base/detoken.lua @@ -139,7 +139,8 @@ end return value else - return expandvalue(value) + -- escape backslashes: they will break loadstring + return expandvalue(value:gsub("\\", "\\\\")) end end diff --git a/tests/base/test_detoken.lua b/tests/base/test_detoken.lua index 7763c883..71fd3294 100644 --- a/tests/base/test_detoken.lua +++ b/tests/base/test_detoken.lua @@ -119,3 +119,13 @@ x = detoken.expand(os.getcwd() .. "/%{cfg.objdir}/file", environ, {paths=true,pathVars=true}) test.isequal("$(IntDir)/file", x) end + +-- +-- Escapes backslashes correctly. +-- + + function suite.escapesBackslashes() + environ.foo = "some/path" + x = detoken.expand("%{foo:gsub('/', '\\')}", environ) + test.isequal("some\\path", x) + end