From b5b5d074ce943f3637e7d9a80d4540ac4d3c2c97 Mon Sep 17 00:00:00 2001 From: Mike Bayer <mike_mp@zzzcomputing.com> Date: Sun, 16 Nov 2008 17:17:18 +0000 Subject: [PATCH] support blank tag attributes --- lib/mako/parsetree.py | 2 +- test/lexer.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/mako/parsetree.py b/lib/mako/parsetree.py index fa18eae..1be6a81 100644 --- a/lib/mako/parsetree.py +++ b/lib/mako/parsetree.py @@ -275,7 +275,7 @@ class Tag(Node): else: if x: expr.append(repr(x)) - self.parsed_attributes[key] = " + ".join(expr) + self.parsed_attributes[key] = " + ".join(expr) or repr('') elif key in nonexpressions: if re.search(r'${.+?}', self.attributes[key]): raise exceptions.CompileException( diff --git a/test/lexer.py b/test/lexer.py index fa5ecef..7ed4fc7 100644 --- a/test/lexer.py +++ b/test/lexer.py @@ -130,7 +130,14 @@ class LexerTest(unittest.TestCase): """ nodes = Lexer(template).parse() assert repr(nodes) == r"""TemplateNode({}, [Text(u'\n \n ', (1, 1)), CallNamespaceTag(u'self:go', {u'x': u'1', u'y': u'2', u'z': u"${'hi' + ' ' + 'there'}"}, (3, 13), []), Text(u'\n ', (3, 64))])""" - + + def test_ns_tag_empty(self): + template = """ + <%form:option value=""></%form:option> + """ + nodes = Lexer(template).parse() + assert repr(nodes) == r"""TemplateNode({}, [Text(u'\n ', (1, 1)), CallNamespaceTag(u'form:option', {u'value': u''}, (2, 13), []), Text(u'\n ', (2, 51))])""" + def test_ns_tag_open(self): template = """ @@ -140,7 +147,7 @@ class LexerTest(unittest.TestCase): """ nodes = Lexer(template).parse() assert repr(nodes) == r"""TemplateNode({}, [Text(u'\n \n ', (1, 1)), CallNamespaceTag(u'self:go', {u'x': u'1', u'y': u'${process()}'}, (3, 13), ["Text(u'\\n this is the body\\n ', (3, 46))"]), Text(u'\n ', (5, 24))])""" - + def test_expr_in_attribute(self): """test some slightly trickier expressions. -- GitLab