diff --git a/cheetah/Compiler.py b/cheetah/Compiler.py index f4c76680..ee558681 100644 --- a/cheetah/Compiler.py +++ b/cheetah/Compiler.py @@ -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( diff --git a/cheetah/Tests/SyntaxAndOutput.py b/cheetah/Tests/SyntaxAndOutput.py index 4fc467c4..e052e6e4 100644 --- a/cheetah/Tests/SyntaxAndOutput.py +++ b/cheetah/Tests/SyntaxAndOutput.py @@ -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 """