diff --git a/lib/mako/parsetree.py b/lib/mako/parsetree.py index fa18eae33fd77c427cdf71e9d9617769ab4f2a93..1be6a819a3c9373e89191a995d1f529a59c0003a 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 fa5ecefe2717d44ec0a20ad9462f0ba567b0f1e3..7ed4fc7bd6712a833776207e1afee90e8e23abc5 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.