From 1e72f30c3ed6bcc4900695d0393019449805348f Mon Sep 17 00:00:00 2001
From: Mike Bayer <mike_mp@zzzcomputing.com>
Date: Sat, 24 Mar 2007 15:07:53 +0000
Subject: [PATCH] - fix to lexing of <%docs> tag nested in other tags

---
 CHANGES           |  1 +
 lib/mako/lexer.py |  2 +-
 test/lexer.py     | 14 ++++++++++++++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/CHANGES b/CHANGES
index 75be870..465380f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,7 @@
   expression-wise from the AST module  [ticket:26]
 - AST parsing, properly detects imports of the form "import foo.bar"
   [ticket:27]
+- fix to lexing of <%docs> tag nested in other tags
   
 0.1.4
 - got defs-within-defs to be cacheable
diff --git a/lib/mako/lexer.py b/lib/mako/lexer.py
index 09c52d4..c871340 100644
--- a/lib/mako/lexer.py
+++ b/lib/mako/lexer.py
@@ -305,7 +305,7 @@ class Lexer(object):
 
     def match_comment(self):
         """matches the multiline version of a comment"""
-        match = self.match(r"<%doc>(.*)</%doc>", re.S)
+        match = self.match(r"<%doc>(.*?)</%doc>", re.S)
         if match:
             self.append_node(parsetree.Comment, match.group(1))
             return True
diff --git a/test/lexer.py b/test/lexer.py
index 7e13edd..fd8ea75 100644
--- a/test/lexer.py
+++ b/test/lexer.py
@@ -398,6 +398,20 @@ hi
 """
         nodes = Lexer(template).parse()
         assert repr(nodes) == r"""TemplateNode({}, [Text(u'\n<style>\n #someselector\n # other non comment stuff\n</style>\n', (1, 1)), Comment(u'a comment', (6, 1)), Text(u'\n# also not a comment\n\n', (7, 1)), Comment(u'this is a comment', (10, 1)), Text(u'   \nthis is ## not a comment\n\n', (11, 1)), Comment(u' multiline\ncomment\n', (14, 1)), Text(u'\n\nhi\n', (16, 8))])"""
+    
+    def test_docs(self):
+        template = """
+        <%doc>
+            this is a comment
+        </%doc>
+        <%def name="foo()">
+            <%doc>
+                this is the foo func
+            </%doc>
+        </%def>
+        """
+        nodes = Lexer(template).parse()
+        assert repr(nodes) == r"""TemplateNode({}, [Text(u'\n        ', (1, 1)), Comment(u'\n            this is a comment\n        ', (2, 9)), Text(u'\n        ', (4, 16)), DefTag(u'def', {u'name': u'foo()'}, (5, 9), ["Text(u'\\n            ', (5, 28))", "Comment(u'\\n                this is the foo func\\n            ', (6, 13))", "Text(u'\\n        ', (8, 20))"]), Text(u'\n        ', (9, 16))])"""
 
     def test_preprocess(self):
         def preproc(text):
-- 
GitLab