From 12d1968e2c7aef1ea86d49116c3cea8dfc178014 Mon Sep 17 00:00:00 2001 From: Juriy Zaytsev Date: Thu, 11 Feb 2010 15:43:18 -0500 Subject: [PATCH] Trim whitespace around values of event handler attributes. More test cases for "javascript:" cleaning. --- src/htmlminifier.js | 2 +- tests/index.html | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) 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); -- 2.34.1