pass NULL Byte to feed() / detect()

This commit is contained in:
PyYoshi 2017-04-25 10:56:21 +09:00
parent da89837a3f
commit 1fdf42d36a
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 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 uchardet_t ud = uchardet_new()
@ -54,7 +54,7 @@ cdef class UniversalDetector:
self._detected_confidence = 0.0
uchardet_reset(self._ud)
def feed(self, const_char_ptr msg):
def feed(self, bytes msg):
cdef int length
cdef int result

View file

@ -114,3 +114,15 @@ class TestCChardet():
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']
)
)