Skip to content

Commit

Permalink
Merge pull request #1275 from LORgames/ssurtees/codeliteFixes
Browse files Browse the repository at this point in the history
Fixed various issues with escaping in CodeLite generator
  • Loading branch information
samsinsane committed Jun 7, 2019
2 parents d561c80 + 4531b0d commit f930e70
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
9 changes: 9 additions & 0 deletions modules/codelite/codelite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 12 additions & 2 deletions modules/codelite/codelite_project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,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
Expand Down Expand Up @@ -288,25 +288,31 @@
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

function m.debugger(cfg)

_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
Expand All @@ -317,9 +323,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
Expand All @@ -328,9 +336,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
Expand Down
50 changes: 38 additions & 12 deletions modules/codelite/tests/test_codelite_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,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
Expand Down Expand Up @@ -155,6 +157,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)
Expand Down Expand Up @@ -188,7 +201,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)
Expand All @@ -200,7 +231,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\""
Expand All @@ -215,7 +246,7 @@ cmd2</StartupCommands>
]]
end

function suite.OnProject_PostBuild()
function suite.OnProjectCfg_PostBuild()
postbuildcommands { "cmd0", "cmd1" }
prepare()
codelite.project.postBuild(prj)
Expand All @@ -227,7 +258,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\""
Expand All @@ -245,7 +276,7 @@ cmd2</StartupCommands>
-- TODO: test custom build


function suite.OnProject_AdditionalRules()
function suite.OnProjectCfg_AdditionalRules()
prepare()
codelite.project.additionalRules(prj)
test.capture [[
Expand All @@ -256,7 +287,7 @@ cmd2</StartupCommands>
]]
end

function suite.OnProject_Completion()
function suite.OnProjectCfg_Completion()
language "C++"
cppdialect "C++11"
prepare()
Expand All @@ -271,11 +302,6 @@ cmd2</StartupCommands>
]]
end


---------------------------------------------------------------------------
-- Setup/Teardown
---------------------------------------------------------------------------

function suite.OnProjectCfg_UnsignedCharOn()
unsignedchar "On"
prepare()
Expand Down

1 comment on commit f930e70

@alex-rass-88
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeLite generator is still broken. Link rules are generated incorrectly.

Please sign in to comment.