Merge pull request #29 from PyYoshi/fix_27

Fix #27
This commit is contained in:
Yoshihiro Misawa 2017-04-25 11:08:13 +09:00 committed by GitHub
commit 9d1d313894
2 changed files with 14 additions and 2 deletions

View file

@ -11,7 +11,7 @@ cdef extern from "uchardet.h":
cdef const_char_ptr uchardet_get_charset(uchardet_t ud) cdef const_char_ptr uchardet_get_charset(uchardet_t ud)
cdef float uchardet_get_confidence(uchardet_t ud) cdef float uchardet_get_confidence(uchardet_t ud)
def detect_with_confidence(const_char_ptr msg): def detect_with_confidence(bytes msg):
cdef int length = len(msg) cdef int length = len(msg)
cdef uchardet_t ud = uchardet_new() cdef uchardet_t ud = uchardet_new()
@ -54,7 +54,7 @@ cdef class UniversalDetector:
self._detected_confidence = 0.0 self._detected_confidence = 0.0
uchardet_reset(self._ud) uchardet_reset(self._ud)
def feed(self, const_char_ptr msg): def feed(self, bytes msg):
cdef int length cdef int length
cdef int result cdef int result

View file

@ -114,3 +114,15 @@ class TestCChardet():
detected_encoding['encoding'].lower() detected_encoding['encoding'].lower()
) )
) )
def test_null_bytes(self):
sample = b'ABC\x00\x80\x81'
detected_encoding = cchardet.detect(sample)
eq_(
None,
detected_encoding['encoding'],
'Expected None, but got %s' % (
detected_encoding['encoding']
)
)