Permalink
Browse files

Find the #encoding directive even if it's after a comment (for example)

Added a test and applied Juan's patch, everything seems to check out
alright with it

Reported-by: Juan Fiol <fiolj@yahoo.com>
  • Loading branch information...
1 parent 46df95c commit 5d931545fcde3029a5e4f49d9d72533c0bd0f667 @rtyler rtyler committed Jan 28, 2010
Showing with 7 additions and 1 deletion.
  1. +1 −1 cheetah/Compiler.py
  2. +6 −0 cheetah/Tests/SyntaxAndOutput.py
View
@@ -1556,7 +1556,7 @@ def __init__(self, source=None, file=None,
else:
unicodeMatch = unicodeDirectiveRE.search(source)
- encodingMatch = encodingDirectiveRE.match(source)
+ encodingMatch = encodingDirectiveRE.search(source)
if unicodeMatch:
if encodingMatch:
raise ParseError(
@@ -742,6 +742,12 @@ def test5(self):
self.verify("#encoding latin-1\nAndr\202",
u'Andr\202')
+ def test6(self):
+ '''Using #encoding on the second line'''
+ self.verify("""### Comments on the first line
+#encoding utf-8\n\xe1\x88\xb4""",
+ u'\u1234', outputEncoding='utf8')
+
class UnicodeDirective(OutputTest):
def test1(self):
"""basic #unicode """

0 comments on commit 5d93154

Please sign in to comment.