From e01e9707225bd23a19e94229abdb2228b031c794 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 6 Jun 2016 09:20:47 -0600 Subject: [PATCH] fix a problem in WXME decoding Thanks to Robby for the test case and for narrowing down the problem. --- gui-lib/mred/private/wxme/stream.rkt | 9 +++++++++ gui-test/tests/gracket/wxme.rkt | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/gui-lib/mred/private/wxme/stream.rkt b/gui-lib/mred/private/wxme/stream.rkt index bb188260..219f6542 100644 --- a/gui-lib/mred/private/wxme/stream.rkt +++ b/gui-lib/mred/private/wxme/stream.rkt @@ -381,6 +381,15 @@ (unless recur? (inc-item-count)) (let ([s (with-handlers ([exn:fail:read? (lambda (x) #f)]) (read si))]) + (when (and recur? s) + ;; It's ok to have extra whitespace when reading a byte + ;; string in a sequence + (let loop () + (define c (peek-byte si)) + (unless (eof-object? c) + (when (char-whitespace? (integer->char c)) + (read-byte si) + (loop))))) (if (or (not s) (not (eof-object? (read-byte si)))) (fail) diff --git a/gui-test/tests/gracket/wxme.rkt b/gui-test/tests/gracket/wxme.rkt index 37b384b8..6e4db8fa 100644 --- a/gui-test/tests/gracket/wxme.rkt +++ b/gui-test/tests/gracket/wxme.rkt @@ -927,6 +927,18 @@ #"") (expect (send fi2 ok?) #f) +(let () + (define (wash-it b) + (define out-base (new editor-stream-out-bytes-base%)) + (define out-stream (make-object editor-stream-out% out-base)) + (send out-stream put (bytes-length b) b) + (define bstr (send out-base get-bytes)) + (define in-base (make-object editor-stream-in-bytes-base% bstr)) + (define in-stream (make-object editor-stream-in% in-base)) + (send in-stream get-unterminated-bytes)) + (define ex-b #"object ... ;;\351\232\234\347\242\215\347\211\251\345\210\227\350\241\250") + (expect (wash-it ex-b) ex-b)) + ;; ---------------------------------------- ;; Save & load