From d4742a06184e5d608dc14c20404f455f08040436 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 20 Jun 2017 14:58:20 -0600 Subject: [PATCH] fix `bytes-convert-end` The `bytes-convert-end` function didn't set up a proper decoding. Make sure that it at least does nothing for encodings where there's nothing to do. --- pkgs/racket-test-core/tests/racket/unicode.rktl | 11 +++++++++++ racket/src/racket/src/string.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkgs/racket-test-core/tests/racket/unicode.rktl b/pkgs/racket-test-core/tests/racket/unicode.rktl index f9c3cdb379..b90757b298 100644 --- a/pkgs/racket-test-core/tests/racket/unicode.rktl +++ b/pkgs/racket-test-core/tests/racket/unicode.rktl @@ -996,6 +996,17 @@ (let-values ([(s2 n2 status2) (bytes-convert c2 s)]) (bytes->string/utf-8 s2))))) +;; Check that `bytes-convert-end` does nothing for UTF-8 and UTF-16 conversion: +(let ([c (bytes-open-converter "platform-UTF-16" "platform-UTF-8")]) + (test-values '(#"" complete) + (lambda () (bytes-convert-end c)))) +(let ([c (bytes-open-converter "platform-UTF-8" "platform-UTF-16")]) + (test-values '(#"" complete) + (lambda () (bytes-convert-end c)))) +(let ([c (bytes-open-converter "UTF-8-permissive" "UTF-8")]) + (test-values '(#"" complete) + (lambda () (bytes-convert-end c)))) + (when (eq? (system-type) 'windows) (let ([c (bytes-open-converter "platform-UTF-8-permissive" "platform-UTF-16")]) ;; Check that we use all 6 bytes of #"\355\240\200\355\260\200" or none diff --git a/racket/src/racket/src/string.c b/racket/src/racket/src/string.c index de05025887..7b86e0dd10 100644 --- a/racket/src/racket/src/string.c +++ b/racket/src/racket/src/string.c @@ -4696,7 +4696,7 @@ static Scheme_Object *convert_one(const char *who, int opos, int argc, Scheme_Ob scheme_get_substring_indices(who, argv[1], argc, argv, 2, 3, &istart, &ifinish); } else { istart = 0; - ifinish = 4; /* This is really a guess about how much space we need for a shift terminator */ + ifinish = 0; } if (argc > opos) {