From 1fdf42d36a974660e8679e9731bf11a5074b8426 Mon Sep 17 00:00:00 2001 From: PyYoshi Date: Tue, 25 Apr 2017 10:56:21 +0900 Subject: [PATCH] pass NULL Byte to feed() / detect() --- src/cchardet/_cchardet.pyx | 4 ++-- src/tests/test.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) 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'] + ) + )