Jackmcbarn has uploaded a new change for review.
https://gerrit.wikimedia.org/r/159629
Change subject: Don't output a semicolon at the end of CSS
......................................................................
Don't output a semicolon at the end of CSS
It's not necessary, it makes the output bigger, and some pages have enough
elements with CSS that it does make an actual difference.
Change-Id: I80d471899c7e04a8a4876c205198a8c0d0b1f281
---
M engines/LuaCommon/lualib/mw.html.lua
M tests/engines/LuaCommon/HtmlLibraryTests.lua
2 files changed, 16 insertions(+), 13 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto
refs/changes/29/159629/1
diff --git a/engines/LuaCommon/lualib/mw.html.lua
b/engines/LuaCommon/lualib/mw.html.lua
index 9462cec..5f0f246 100644
--- a/engines/LuaCommon/lualib/mw.html.lua
+++ b/engines/LuaCommon/lualib/mw.html.lua
@@ -82,7 +82,8 @@
--
-- @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 @@
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 de69828..b448056 100644
--- a/tests/engines/LuaCommon/HtmlLibraryTests.lua
+++ b/tests/engines/LuaCommon/HtmlLibraryTests.lua
@@ -207,11 +207,11 @@
},
{ name = 'mw.html.css', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'css', 'foo', 'bar' },
- expect = { '<div style="foo:bar;"></div>' }
+ expect = { '<div style="foo:bar"></div>' }
},
{ name = 'mw.html.css (numeric arguments)', func = testHelper,
type='ToString',
args = { getEmptyTestDiv(), 'css', 123, 456 },
- expect = { '<div style="123:456;"></div>' }
+ expect = { '<div style="123:456"></div>' }
},
{ name = 'mw.html.css (nil noop)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'css', 'foo', nil },
@@ -231,7 +231,7 @@
},
{ name = 'mw.html.css (table)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'css', testAttrs },
- expect = { '<div style="ab:cd;foo:bar;"></div>' }
+ expect = { '<div style="ab:cd;foo:bar"></div>' }
},
{ name = 'mw.html.css (invalid table)', func = testHelper,
type='ToString',
args = { getEmptyTestDiv(), 'css', { foo = 'bar', ab = true } },
@@ -239,11 +239,11 @@
},
{ name = 'mw.html.cssText', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'cssText', 'Unit tests, ftw' },
- expect = { '<div style="Unit tests, ftw;"></div>' }
+ expect = { '<div style="Unit tests, ftw"></div>' }
},
{ name = 'mw.html.cssText (numeric argument)', func = testHelper,
type='ToString',
args = { getEmptyTestDiv(), 'cssText', 123 },
- expect = { '<div style="123;"></div>' }
+ expect = { '<div style="123"></div>' }
},
{ name = 'mw.html.cssText (invalid value)', func = testHelper,
type='ToString',
args = { getEmptyTestDiv(), 'cssText', {} },
@@ -263,11 +263,11 @@
},
{ name = 'mw.html attribute escaping (CSS)', func = testHelper,
type='ToString',
args = { getEmptyTestDiv(), 'css', 'mu"ha', 'ha"ha' },
- expect = { '<div style="mu"ha:ha"ha;"></div>' }
+ expect = { '<div style="mu"ha:ha"ha"></div>' }
},
{ name = 'mw.html attribute escaping (CSS raw)', func = testHelper,
type='ToString',
args = { getEmptyTestDiv(), 'cssText', 'mu"ha:-ha"ha' },
- expect = { '<div style="mu"ha:-ha"ha;"></div>' }
+ expect = { '<div style="mu"ha:-ha"ha"></div>' }
},
{ name = 'mw.html.addClass (nil)', func = testHelper, type='ToString',
args = { getEmptyTestDiv(), 'addClass' },
@@ -284,7 +284,7 @@
expect = { '<div class="foo bar"></div>' }
},
{ name = 'mw.html.css.cssText.css', func = testCssAndCssText,
type='ToString',
- expect = { '<div style="foo:bar;abc:def;g:h;"></div>' }
+ expect = { '<div style="foo:bar;abc:def;g:h"></div>' }
},
{ name = 'mw.html.tag (using done)', func = testTagDone,
type='ToString',
expect = { '<div><span></span></div>' }
@@ -330,7 +330,7 @@
{ name = 'mw.html complex test', func = testComplex, type='ToString',
expect = {
'<div class="firstClass" what="ever"><meh whynot="Русский"><hr
a="b" /></meh>' ..
- '<hr /><div abc="def" style="width:-1px;"></div></div>'
+ '<hr /><div abc="def" style="width:-1px"></div></div>'
}
},
}
--
To view, visit https://gerrit.wikimedia.org/r/159629
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I80d471899c7e04a8a4876c205198a8c0d0b1f281
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Jackmcbarn <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits