Fixed various issues with escaping in CodeLite generator

This commit is contained in:
Sam Surtees 2019-05-02 02:37:22 +10:00
parent 5913b0ebaa
commit 4531b0de4a
No known key found for this signature in database
GPG Key ID: CB8B652DAC0692A1
3 changed files with 59 additions and 14 deletions

View File

@ -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('<', '&lt;')
result = result:gsub('>', '&gt;')
return result
end
function codelite.esc(value)
local result = value:gsub('&', '&amp;')
result = result:gsub('<', '&lt;')
result = result:gsub('>', '&gt;')
result = result:gsub('"', '\\&quot;')
return result
end

View File

@ -207,7 +207,7 @@
_x(4, '<IncludePath Value="%s"/>', project.getrelative(cfg.project, includedir))
end
for _, define in ipairs(cfg.defines) do
_x(4, '<Preprocessor Value="%s"/>', p.esc(define))
_p(4, '<Preprocessor Value="%s"/>', p.esc(define):gsub(' ', '\\ '))
end
_p(3, '</Compiler>')
end
@ -287,7 +287,7 @@
local envs = table.concat(cfg.debugenvs, "\n")
_p(3, '<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">')
_x(4, '<![CDATA[%s]]>', envs)
_p(4, '<![CDATA[%s]]>', envs)
_p(3, '</Environment>')
end
@ -295,17 +295,23 @@
_p(3, '<Debugger IsRemote="%s" RemoteHostName="%s" RemoteHostPort="%s" DebuggerPath="" IsExtended="%s">', 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, '<DebuggerSearchPaths>%s</DebuggerSearchPaths>', table.concat(p.esc(project.getrelative(cfg.project, cfg.debugsearchpaths)), "\n"))
p.escaper(codelite.esc)
else
_p(4, '<DebuggerSearchPaths/>')
end
if #cfg.debugconnectcommands > 0 then
p.escaper(codelite.escElementText)
_p(4, '<PostConnectCommands>%s</PostConnectCommands>', table.concat(p.esc(cfg.debugconnectcommands), "\n"))
p.escaper(codelite.esc)
else
_p(4, '<PostConnectCommands/>')
end
if #cfg.debugstartupcommands > 0 then
p.escaper(codelite.escElementText)
_p(4, '<StartupCommands>%s</StartupCommands>', table.concat(p.esc(cfg.debugstartupcommands), "\n"))
p.escaper(codelite.esc)
else
_p(4, '<StartupCommands/>')
end
@ -316,9 +322,11 @@
if #cfg.prebuildcommands > 0 then
_p(3, '<PreBuild>')
local commands = os.translateCommandsAndPaths(cfg.prebuildcommands, cfg.project.basedir, cfg.project.location)
p.escaper(codelite.escElementText)
for _, command in ipairs(commands) do
_x(4, '<Command Enabled="yes">%s</Command>', command)
end
p.escaper(codelite.esc)
_p(3, '</PreBuild>')
end
end
@ -327,9 +335,11 @@
if #cfg.postbuildcommands > 0 then
_p(3, '<PostBuild>')
local commands = os.translateCommandsAndPaths(cfg.postbuildcommands, cfg.project.basedir, cfg.project.location)
p.escaper(codelite.escElementText)
for _, command in ipairs(commands) do
_x(4, '<Command Enabled="yes">%s</Command>', command)
end
p.escaper(codelite.esc)
_p(3, '</PostBuild>')
end
end

View File

@ -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 [[
<Compiler Options="" C_Options="" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" UseDifferentPCHFlags="no" PCHFlags="">
<Preprocessor Value="TEST"/>
<Preprocessor Value="DEF"/>
<Preprocessor Value="VAL=1"/>
<Preprocessor Value="ESCAPE=\&quot;WITH\ SPACE\&quot;"/>
</Compiler>
]]
end
@ -154,6 +156,17 @@
)
end
function suite.OnProjectCfg_EnvironmentEscaping()
debugenvs { "\"ENV\"=<&>" }
prepare()
codelite.project.environment(cfg)
test.capture(
' <Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">\n' ..
' <![CDATA["ENV"=<&>]]>\n' ..
' </Environment>'
)
end
function suite.OnProjectCfg_Debugger()
prepare()
codelite.project.debugger(cfg)
@ -187,7 +200,25 @@ cmd2</StartupCommands>
]]
end
function suite.OnProject_PreBuild()
function suite.OnProjectCfg_DebuggerOptsEscaping()
debugremotehost "localhost"
debugport(2345)
debugextendedprotocol(true)
debugsearchpaths { "\"search\" && <path>" }
debugconnectcommands { "\"connect\" && <cmd>" }
debugstartupcommands { "\"start\" && <cmd>" }
prepare()
codelite.project.debugger(cfg)
test.capture [[
<Debugger IsRemote="yes" RemoteHostName="localhost" RemoteHostPort="2345" DebuggerPath="" IsExtended="yes">
<DebuggerSearchPaths>"search" &amp;&amp; &lt;path&gt;</DebuggerSearchPaths>
<PostConnectCommands>"connect" &amp;&amp; &lt;cmd&gt;</PostConnectCommands>
<StartupCommands>"start" &amp;&amp; &lt;cmd&gt;</StartupCommands>
</Debugger>
]]
end
function suite.OnProjectCfg_PreBuild()
prebuildcommands { "cmd0", "cmd1" }
prepare()
codelite.project.preBuild(prj)
@ -199,7 +230,7 @@ cmd2</StartupCommands>
]]
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</StartupCommands>
]]
end
function suite.OnProject_PostBuild()
function suite.OnProjectCfg_PostBuild()
postbuildcommands { "cmd0", "cmd1" }
prepare()
codelite.project.postBuild(prj)
@ -226,7 +257,7 @@ cmd2</StartupCommands>
]]
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</StartupCommands>
-- TODO: test custom build
function suite.OnProject_AdditionalRules()
function suite.OnProjectCfg_AdditionalRules()
prepare()
codelite.project.additionalRules(prj)
test.capture [[
@ -255,7 +286,7 @@ cmd2</StartupCommands>
]]
end
function suite.OnProject_Completion()
function suite.OnProjectCfg_Completion()
language "C++"
cppdialect "C++11"
prepare()
@ -270,11 +301,6 @@ cmd2</StartupCommands>
]]
end
---------------------------------------------------------------------------
-- Setup/Teardown
---------------------------------------------------------------------------
function suite.OnProjectCfg_UnsignedCharOn()
unsignedchar "On"
prepare()