From 4531b0de4a4357d8091695f84950f868fcafc0d1 Mon Sep 17 00:00:00 2001 From: Sam Surtees Date: Thu, 2 May 2019 02:37:22 +1000 Subject: [PATCH] Fixed various issues with escaping in CodeLite generator --- modules/codelite/codelite.lua | 9 ++++ modules/codelite/codelite_project.lua | 14 +++++- .../codelite/tests/test_codelite_config.lua | 50 ++++++++++++++----- 3 files changed, 59 insertions(+), 14 deletions(-) diff --git a/modules/codelite/codelite.lua b/modules/codelite/codelite.lua index 6f3e93131f..16dbc623e9 100755 --- a/modules/codelite/codelite.lua +++ b/modules/codelite/codelite.lua @@ -26,10 +26,19 @@ return cfgname end + -- Element text is not escaped the same as element attributes + function codelite.escElementText(value) + local result = value:gsub('&', '&') + result = result:gsub('<', '<') + result = result:gsub('>', '>') + return result + end + function codelite.esc(value) local result = value:gsub('&', '&') result = result:gsub('<', '<') result = result:gsub('>', '>') + result = result:gsub('"', '\\"') return result end diff --git a/modules/codelite/codelite_project.lua b/modules/codelite/codelite_project.lua index c9c9469bf9..3d40b8bb25 100755 --- a/modules/codelite/codelite_project.lua +++ b/modules/codelite/codelite_project.lua @@ -207,7 +207,7 @@ _x(4, '', project.getrelative(cfg.project, includedir)) end for _, define in ipairs(cfg.defines) do - _x(4, '', p.esc(define)) + _p(4, '', p.esc(define):gsub(' ', '\\ ')) end _p(3, '') end @@ -287,7 +287,7 @@ local envs = table.concat(cfg.debugenvs, "\n") _p(3, '') - _x(4, '', envs) + _p(4, '', envs) _p(3, '') end @@ -295,17 +295,23 @@ _p(3, '', iif(cfg.debugremotehost, "yes", "no"), cfg.debugremotehost or "", iif(cfg.debugport, tostring(cfg.debugport), ""), iif(cfg.debugextendedprotocol, "yes", "no")) if #cfg.debugsearchpaths > 0 then + p.escaper(codelite.escElementText) _p(4, '%s', table.concat(p.esc(project.getrelative(cfg.project, cfg.debugsearchpaths)), "\n")) + p.escaper(codelite.esc) else _p(4, '') end if #cfg.debugconnectcommands > 0 then + p.escaper(codelite.escElementText) _p(4, '%s', table.concat(p.esc(cfg.debugconnectcommands), "\n")) + p.escaper(codelite.esc) else _p(4, '') end if #cfg.debugstartupcommands > 0 then + p.escaper(codelite.escElementText) _p(4, '%s', table.concat(p.esc(cfg.debugstartupcommands), "\n")) + p.escaper(codelite.esc) else _p(4, '') end @@ -316,9 +322,11 @@ if #cfg.prebuildcommands > 0 then _p(3, '') local commands = os.translateCommandsAndPaths(cfg.prebuildcommands, cfg.project.basedir, cfg.project.location) + p.escaper(codelite.escElementText) for _, command in ipairs(commands) do _x(4, '%s', command) end + p.escaper(codelite.esc) _p(3, '') end end @@ -327,9 +335,11 @@ if #cfg.postbuildcommands > 0 then _p(3, '') local commands = os.translateCommandsAndPaths(cfg.postbuildcommands, cfg.project.basedir, cfg.project.location) + p.escaper(codelite.escElementText) for _, command in ipairs(commands) do _x(4, '%s', command) end + p.escaper(codelite.esc) _p(3, '') end end diff --git a/modules/codelite/tests/test_codelite_config.lua b/modules/codelite/tests/test_codelite_config.lua index 46e431d09b..bfba26b38c 100644 --- a/modules/codelite/tests/test_codelite_config.lua +++ b/modules/codelite/tests/test_codelite_config.lua @@ -68,13 +68,15 @@ end function suite.OnProjectCfg_Defines() - defines { "TEST", "DEF" } + defines { "TEST", "DEF", "VAL=1", "ESCAPE=\"WITH SPACE\"" } prepare() codelite.project.compiler(cfg) test.capture [[ + + ]] end @@ -154,6 +156,17 @@ ) end + function suite.OnProjectCfg_EnvironmentEscaping() + debugenvs { "\"ENV\"=<&>" } + prepare() + codelite.project.environment(cfg) + test.capture( +' \n' .. +' ]]>\n' .. +' ' + ) + end + function suite.OnProjectCfg_Debugger() prepare() codelite.project.debugger(cfg) @@ -187,7 +200,25 @@ cmd2 ]] end - function suite.OnProject_PreBuild() + function suite.OnProjectCfg_DebuggerOptsEscaping() + debugremotehost "localhost" + debugport(2345) + debugextendedprotocol(true) + debugsearchpaths { "\"search\" && " } + debugconnectcommands { "\"connect\" && " } + debugstartupcommands { "\"start\" && " } + prepare() + codelite.project.debugger(cfg) + test.capture [[ + + "search" && <path> + "connect" && <cmd> + "start" && <cmd> + + ]] + end + + function suite.OnProjectCfg_PreBuild() prebuildcommands { "cmd0", "cmd1" } prepare() codelite.project.preBuild(prj) @@ -199,7 +230,7 @@ cmd2 ]] end - function suite.OnProject_PreBuild_Escaped() + function suite.OnProjectCfg_PreBuild_Escaped() prebuildcommands { "touch \"./build/copyright\" && echo OK", "cat \"./lib/copyright\" >> \"./build/copyright\"" @@ -214,7 +245,7 @@ cmd2 ]] end - function suite.OnProject_PostBuild() + function suite.OnProjectCfg_PostBuild() postbuildcommands { "cmd0", "cmd1" } prepare() codelite.project.postBuild(prj) @@ -226,7 +257,7 @@ cmd2 ]] end - function suite.OnProject_PostBuild_Escaped() + function suite.OnProjectCfg_PostBuild_Escaped() postbuildcommands { "touch \"./build/copyright\" && echo OK", "cat \"./lib/copyright\" >> \"./build/copyright\"" @@ -244,7 +275,7 @@ cmd2 -- TODO: test custom build - function suite.OnProject_AdditionalRules() + function suite.OnProjectCfg_AdditionalRules() prepare() codelite.project.additionalRules(prj) test.capture [[ @@ -255,7 +286,7 @@ cmd2 ]] end - function suite.OnProject_Completion() + function suite.OnProjectCfg_Completion() language "C++" cppdialect "C++11" prepare() @@ -270,11 +301,6 @@ cmd2 ]] end - ---------------------------------------------------------------------------- --- Setup/Teardown ---------------------------------------------------------------------------- - function suite.OnProjectCfg_UnsignedCharOn() unsignedchar "On" prepare()