diff --git a/engines/LuaCommon/lualib/mw.html.lua b/engines/LuaCommon/lualib/mw.html.lua index 9462cecc..5f0f2464 100644 --- a/engines/LuaCommon/lualib/mw.html.lua +++ b/engines/LuaCommon/lualib/mw.html.lua @@ -82,7 +82,8 @@ end -- -- @param s local function htmlEncode( s ) - return string.gsub( s, '[<>&"]', htmlencodeMap ) + -- The parentheses ensure that there is only one return value + return ( string.gsub( s, '[<>&"]', htmlencodeMap ) ) end local function cssEncode( s ) @@ -104,16 +105,18 @@ methodtable._build = function( t, ret ) end if #t.styles > 0 then table.insert( ret, ' style="' ) + local css = {} for i, prop in ipairs( t.styles ) do if type( prop ) ~= 'table' then -- added with cssText() - table.insert( ret, htmlEncode( prop ) .. ';' ) + table.insert( css, htmlEncode( prop ) ) else -- added with css() table.insert( - ret, - htmlEncode( cssEncode( prop.name ) .. ':' .. cssEncode( prop.val ) ) .. ';' + css, + htmlEncode( cssEncode( prop.name ) .. ':' .. cssEncode( prop.val ) ) ) end end + table.insert( ret, table.concat( css, ';' ) ) table.insert( ret, '"' ) end if t.selfClosing then diff --git a/tests/engines/LuaCommon/HtmlLibraryTests.lua b/tests/engines/LuaCommon/HtmlLibraryTests.lua index de698288..b4480561 100644 --- a/tests/engines/LuaCommon/HtmlLibraryTests.lua +++ b/tests/engines/LuaCommon/HtmlLibraryTests.lua @@ -207,11 +207,11 @@ local tests = { }, { name = 'mw.html.css', func = testHelper, type='ToString', args = { getEmptyTestDiv(), 'css', 'foo', 'bar' }, - expect = { '
' } + expect = { '' } }, { name = 'mw.html.css (numeric arguments)', func = testHelper, type='ToString', args = { getEmptyTestDiv(), 'css', 123, 456 }, - expect = { '' } + expect = { '' } }, { name = 'mw.html.css (nil noop)', func = testHelper, type='ToString', args = { getEmptyTestDiv(), 'css', 'foo', nil }, @@ -231,7 +231,7 @@ local tests = { }, { name = 'mw.html.css (table)', func = testHelper, type='ToString', args = { getEmptyTestDiv(), 'css', testAttrs }, - expect = { '' } + expect = { '' } }, { name = 'mw.html.css (invalid table)', func = testHelper, type='ToString', args = { getEmptyTestDiv(), 'css', { foo = 'bar', ab = true } }, @@ -239,11 +239,11 @@ local tests = { }, { name = 'mw.html.cssText', func = testHelper, type='ToString', args = { getEmptyTestDiv(), 'cssText', 'Unit tests, ftw' }, - expect = { '' } + expect = { '' } }, { name = 'mw.html.cssText (numeric argument)', func = testHelper, type='ToString', args = { getEmptyTestDiv(), 'cssText', 123 }, - expect = { '' } + expect = { '' } }, { name = 'mw.html.cssText (invalid value)', func = testHelper, type='ToString', args = { getEmptyTestDiv(), 'cssText', {} }, @@ -263,11 +263,11 @@ local tests = { }, { name = 'mw.html attribute escaping (CSS)', func = testHelper, type='ToString', args = { getEmptyTestDiv(), 'css', 'mu"ha', 'ha"ha' }, - expect = { '' } + expect = { '' } }, { name = 'mw.html attribute escaping (CSS raw)', func = testHelper, type='ToString', args = { getEmptyTestDiv(), 'cssText', 'mu"ha:-ha"ha' }, - expect = { '' } + expect = { '' } }, { name = 'mw.html.addClass (nil)', func = testHelper, type='ToString', args = { getEmptyTestDiv(), 'addClass' }, @@ -284,7 +284,7 @@ local tests = { expect = { '' } }, { name = 'mw.html.css.cssText.css', func = testCssAndCssText, type='ToString', - expect = { '' } + expect = { '' } }, { name = 'mw.html.tag (using done)', func = testTagDone, type='ToString', expect = { '