Commit 5b8bcedb authored by Stefan Behnel's avatar Stefan Behnel

Ignore the "c_string_encoding" directive when looking for a "coding" cookie in...

Ignore the "c_string_encoding" directive when looking for a "coding" cookie in the first two source lines.
Closes #2632.
parent 7f5f839d
......@@ -148,6 +148,10 @@ Bugs fixed
the return value was non-null.
Original patch by Matt Wozniski (Github Issue #2603)
* The source file encoding detection could get confused if the
``c_string_encoding`` directive appeared within the first two lines.
(Github issue #2632)
Other changes
-------------
......
......@@ -238,7 +238,7 @@ def decode_filename(filename):
# support for source file encoding detection
_match_file_encoding = re.compile(b"coding[:=]\s*([-\w.]+)").search
_match_file_encoding = re.compile(br"(\w*coding)[:=]\s*([-\w.]+)").search
def detect_opened_file_encoding(f):
......@@ -254,8 +254,8 @@ def detect_opened_file_encoding(f):
if not data:
break
m = _match_file_encoding(lines[0])
if m:
return m.group(1).decode('iso8859-1')
if m and m.group(1) != b'c_string_encoding':
return m.group(2).decode('iso8859-1')
elif len(lines) > 1:
m = _match_file_encoding(lines[1])
if m:
......
# cython: c_string_type = str
# cython: c_string_encoding = default
# cython: c_string_encoding=default
# cython: c_string_type=str
# NOTE: the directive order above is specifically meant to trigger (and confuse) the
# source encoding detector with "coding=default".
import sys
if sys.version_info[0] >= 3:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment