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 ...@@ -148,6 +148,10 @@ Bugs fixed
the return value was non-null. the return value was non-null.
Original patch by Matt Wozniski (Github Issue #2603) 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 Other changes
------------- -------------
......
...@@ -238,7 +238,7 @@ def decode_filename(filename): ...@@ -238,7 +238,7 @@ def decode_filename(filename):
# support for source file encoding detection # 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): def detect_opened_file_encoding(f):
...@@ -254,8 +254,8 @@ def detect_opened_file_encoding(f): ...@@ -254,8 +254,8 @@ def detect_opened_file_encoding(f):
if not data: if not data:
break break
m = _match_file_encoding(lines[0]) m = _match_file_encoding(lines[0])
if m: if m and m.group(1) != b'c_string_encoding':
return m.group(1).decode('iso8859-1') return m.group(2).decode('iso8859-1')
elif len(lines) > 1: elif len(lines) > 1:
m = _match_file_encoding(lines[1]) m = _match_file_encoding(lines[1])
if m: 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 import sys
if sys.version_info[0] >= 3: 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