From: Juriy Zaytsev Date: Thu, 11 Feb 2010 20:43:18 +0000 (-0500) Subject: Trim whitespace around values of event handler attributes. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=12d1968e2c7aef1ea86d49116c3cea8dfc178014;p=html-minifier.git Trim whitespace around values of event handler attributes. More test cases for "javascript:" cleaning. --- diff --git a/src/htmlminifier.js b/src/htmlminifier.js index d9b419b..e2321c2 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -78,7 +78,7 @@ function cleanAttributeValue(tag, attrName, attrValue) { if (/^on[a-z]+/.test(attrName)) { - return attrValue.replace(/^\s*javascript:/i, ''); + return trimWhitespace(attrValue.replace(/^\s*javascript:\s*/i, '')); } if (attrName === 'class') { // trim and collapse whitesapce diff --git a/tests/index.html b/tests/index.html index 862ce3b..d2b567b 100644 --- a/tests/index.html +++ b/tests/index.html @@ -167,13 +167,7 @@ }); test('cleaning attributes', function(){ - var input = '

x

'; - equals(minify(input, { cleanAttributes: true }), '

x

'); - - input = '

x

'; - equals(minify(input, { cleanAttributes: true, removeAttributeQuotes: true }), '

x

'); - - input = '

foo bar baz

'; + var input = '

foo bar baz

', output; equals(minify(input, { cleanAttributes: true }), '

foo bar baz

'); input = '

foo bar baz

'; @@ -185,6 +179,24 @@ input = '

foo bar baz

'; equals(minify(input, { cleanAttributes: true }), '

foo bar baz

'); + + input = 'blah'; + output = 'blah'; + equals(minify(input, { cleanAttributes: true }), output); + }); + + test('removing redundant attributes (... = "javascript: ...")', function(){ + var input = '

x

'; + equals(minify(input, { cleanAttributes: true }), '

x

'); + + input = '

x

'; + equals(minify(input, { cleanAttributes: true, removeAttributeQuotes: true }), '

x

'); + + input = '

x

'; + equals(minify(input, { cleanAttributes: true }), '

x

'); + + input = '

x

'; + equals(minify(input, { cleanAttributes: true }), input); }); test('removing attribute quotes', function(){ @@ -252,6 +264,8 @@ equals(minify(input, { removeEmptyElements: true }), output); }); + + })(this);