diff --git a/src/cchardet/_cchardet.pyx b/src/cchardet/_cchardet.pyx index 690d5f3..75af096 100644 --- a/src/cchardet/_cchardet.pyx +++ b/src/cchardet/_cchardet.pyx @@ -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 diff --git a/src/tests/test.py b/src/tests/test.py index 879fae5..2723ce0 100644 --- a/src/tests/test.py +++ b/src/tests/test.py @@ -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'] + ) + )