Skip to content

Commit

Permalink
Merge pull request #34 from avacariu/master
Browse files Browse the repository at this point in the history
Leave quotes around attributes containing =, <, >, and `
  • Loading branch information
mankyd committed Aug 25, 2017
2 parents 6831a2b + 2463e28 commit 2877618
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion htmlmin/escape.py
Expand Up @@ -30,6 +30,8 @@
except ImportError:
from cgi import escape

import re

NO_QUOTES = 0
SINGLE_QUOTE = 1
DOUBLE_QUOTE = 2
Expand Down Expand Up @@ -62,7 +64,7 @@ def escape_attr_value(val, double_quote=False):
elif "'" in val:
return (val, DOUBLE_QUOTE)

if not val or any((c.isspace() for c in val)):
if not val or any((c.isspace() for c in val)) or re.search(r"[=><`]", val):
return (val, DOUBLE_QUOTE)
return (val, NO_QUOTES)

Expand Down
3 changes: 3 additions & 0 deletions htmlmin/tests/test_escape.py
Expand Up @@ -61,6 +61,9 @@ def test_quote_space(self):
self.assertDoubleQuote(" foobar ", " foobar ")
self.assertDoubleQuote("", "")

def test_quote_equal(self):
self.assertDoubleQuote("width=device-width", "width=device-width")

def test_force_double_quote(self):
result = escape.escape_attr_value("foobar", double_quote=True)
self.assertEqual('foobar', result[0])
Expand Down
4 changes: 2 additions & 2 deletions htmlmin/tests/tests.py
Expand Up @@ -327,14 +327,14 @@ def test_basic_minification_quality(self):
with codecs.open('htmlmin/tests/large_test.html', encoding='utf-8') as inpf:
inp = inpf.read()
out = self.minify(inp)
self.assertEqual(len(inp) - len(out), 9579)
self.assertEqual(len(inp) - len(out), 9383)

def test_high_minification_quality(self):
import codecs
with codecs.open('htmlmin/tests/large_test.html', encoding='utf-8') as inpf:
inp = inpf.read()
out = self.minify(inp, remove_all_empty_space=True, remove_comments=True)
self.assertEqual(len(inp) - len(out), 12693)
self.assertEqual(len(inp) - len(out), 12497)

class TestMinifierObject(HTMLMinTestCase):
__reference_texts__ = MINIFY_FUNCTION_TEXTS
Expand Down

0 comments on commit 2877618

Please sign in to comment.