From 6b7c1a70d75af1a43d7f7a353f08bc13feb90f19 Mon Sep 17 00:00:00 2001 From: Juriy Zaytsev Date: Sat, 13 Mar 2010 17:16:56 -0500 Subject: [PATCH] Trim whitespace in style attributes. --- src/htmlminifier.js | 4 ++-- tests/index.html | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 1a3f0e4..56a49b9 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -91,12 +91,12 @@ function cleanAttributeValue(tag, attrName, attrValue) { if (isEventAttribute(attrName)) { - return trimWhitespace(attrValue.replace(/^\s*javascript:\s*/i, '')); + return trimWhitespace(attrValue).replace(/^javascript:\s*/i, ''); } else if (attrName === 'class') { return collapseWhitespace(trimWhitespace(attrValue)); } - else if (isUriTypeAttribute(attrName)) { + else if (isUriTypeAttribute(attrName) || attrName === 'style') { return trimWhitespace(attrValue); } return attrValue; diff --git a/tests/index.html b/tests/index.html index 3905733..b8148b1 100644 --- a/tests/index.html +++ b/tests/index.html @@ -203,7 +203,7 @@ equals(minify(input, { removeEmptyAttributes: true }), ''); }); - test('cleaning class attributes', function(){ + test('cleaning class/style attributes', function(){ input = '

foo bar baz

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

foo bar baz

'); @@ -212,10 +212,16 @@ equals(minify(input, { cleanAttributes: true, removeAttributeQuotes: true }), '

foo bar baz

'); input = '

foo bar baz

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

foo bar baz

'); + output = '

foo bar baz

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

foo bar baz

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

foo bar baz

'); + output = '

foo bar baz

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

'; + output = '

'; + equals(minify(input, { cleanAttributes: true }), output); }); test('cleaning URI-based attributes', function(){ @@ -256,6 +262,10 @@ input = 'blah'; output = 'blah'; equals(minify(input, { cleanAttributes: true }), output); + + input = '

x'; + output = '

x

'; + equals(minify(input, { cleanAttributes: true }), output); }); test('removing redundant attributes (<form method="get" ...>)', function(){ -- 2.34.1