Skip to content

Commit

Permalink
- Removed errant "lower()" in the lexer which
Browse files Browse the repository at this point in the history
  was causing tags to compile with
  case-insensitive names, thus messing up
  custom <%call> names. [ticket:108]
  • Loading branch information
zzzeek committed Apr 19, 2009
1 parent 43b362d commit b06cd0f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@

- Fixed lexing support for whitespace
around '=' sign in defs. [ticket:102]

- Removed errant "lower()" in the lexer which
was causing tags to compile with
case-insensitive names, thus messing up
custom <%call> names. [ticket:108]

0.2.4
- Fixed compatibility with Jython 2.5b1.
Expand Down
2 changes: 1 addition & 1 deletion lib/mako/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def match_tag_start(self):
re.I | re.S | re.X)

if match:
(keyword, attr, isend) = (match.group(1).lower(), match.group(2), match.group(3))
(keyword, attr, isend) = (match.group(1), match.group(2), match.group(3))
self.keyword = keyword
attributes = {}
if attr:
Expand Down
1 change: 0 additions & 1 deletion test/def.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def test_def_blankargs(self):
${mycomp()}""")
assert template.render(variable='hi').strip() == """hello mycomp hi"""


def test_def_args(self):
template = Template("""
<%def name="mycomp(a, b)">
Expand Down
39 changes: 14 additions & 25 deletions test/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ def test_onlyclosed_tag(self):
hi.
"""
try:
nodes = Lexer(template).parse()
assert False
except exceptions.SyntaxException, e:
assert str(e) == "Closing tag without opening tag: </%namespace> at line: 6 char: 13"
self.assertRaises(exceptions.SyntaxException, Lexer(template).parse)

def test_unmatched_tag(self):
template = """
Expand All @@ -58,22 +54,23 @@ def test_unmatched_tag(self):
hi.
"""
try:
nodes = Lexer(template).parse()
assert False
except exceptions.SyntaxException, e:
assert str(e) == "Closing tag </%namespace> does not match tag: <%def> at line: 5 char: 13"
self.assertRaises(exceptions.SyntaxException, Lexer(template).parse)

def test_nonexistent_tag(self):
template = """
<%lala x="5"/>
"""
try:
node = Lexer(template).parse()
assert False
except exceptions.CompileException, e:
assert str(e) == "No such tag: 'lala' at line: 2 char: 13"
self.assertRaises(exceptions.CompileException, Lexer(template).parse)

def test_wrongcase_tag(self):
template = """
<%DEF name="foo()">
</%def>
"""

self.assertRaises(exceptions.CompileException, Lexer(template).parse)

def test_text_tag(self):
template = """
## comment
Expand Down Expand Up @@ -105,23 +102,15 @@ def test_def_syntax(self):
hi
</%def>
"""
try:
node = Lexer(template).parse()
assert False
except exceptions.CompileException, e:
assert str(e) == "Missing attribute(s): 'name' at line: 2 char: 9"
self.assertRaises(exceptions.CompileException, Lexer(template).parse)

def test_def_syntax_2(self):
template = """
<%def name="lala">
hi
</%def>
"""
try:
node = Lexer(template).parse()
assert False
except exceptions.CompileException, e:
assert str(e) == "Missing parenthesis in %def at line: 2 char: 9"
self.assertRaises(exceptions.CompileException, Lexer(template).parse)

def test_whitespace_equals(self):
template = """
Expand Down
16 changes: 16 additions & 0 deletions test/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,23 @@ def test_custom_tag_3(self):
"call body"
]

def test_custom_tag_case_sensitive(self):
t = Template("""
<%def name="renderPanel()">
panel ${caller.body()}
</%def>
<%def name="renderTablePanel()">
<%self:renderPanel>
hi
</%self:renderPanel>
</%def>
<%self:renderTablePanel/>
""")
assert result_lines(t.render()) == ['panel', 'hi']


def test_expr_grouping(self):
"""test that parenthesis are placed around string-embedded expressions."""

Expand Down

0 comments on commit b06cd0f

Please sign in to comment.