Skip to content

Commit

Permalink
Find the #encoding directive even if it's after a comment (for example)
Browse files Browse the repository at this point in the history
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
R. Tyler Ballance committed Jan 28, 2010
1 parent 46df95c commit 5d93154
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cheetah/Compiler.py
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions cheetah/Tests/SyntaxAndOutput.py
Expand Up @@ -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 """
Expand Down

0 comments on commit 5d93154

Please sign in to comment.