From f7abd8ebe1c2133de14bde93297cb761494abfe7b5955158b0cd5cf87dc03023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Bj=C3=B6rnstam?= Date: Mon, 23 Nov 2026 14:01:18 +0100 Subject: [PATCH 1/2] Follow bytes->string returning a Result - A device file whose document is not UTF-8 is an error: "the document in it is not UTF-8". - A page title that does not decode in its charset is read as Windows-1252, by matching the result rather than catching. - Hex digits, charset names and the tests' response heads are read with bytes->string/lossy. Co-Authored-By: Claude Opus 5.5 --- src/bookmark.bjo | 2 +- src/store.bjo | 3 ++- src/title.bjo | 6 +++--- tests/title.bjo | 2 +- tests/wayback.bjo | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/bookmark.bjo b/src/bookmark.bjo index 06f9867..19e6044 100644 --- a/src/bookmark.bjo +++ b/src/bookmark.bjo @@ -169,7 +169,7 @@ (when (>= i 0) (set! out i (get hex-digits (cast int (bitwise-and rest 15L)))) (go (- i 1) (shift-right rest 4)))) - (bytes->string out)) + (bytes->string/lossy out)) ;; The value of the lower-case hex digits of `bytes` from `start` to `end`. ;; `None` for any other byte. diff --git a/src/store.bjo b/src/store.bjo index 3705a3e..a106b17 100644 --- a/src/store.bjo +++ b/src/store.bjo @@ -329,7 +329,8 @@ (:def (Some contents) (aead-decrypt dek nonce sealed #:aad header) :leave-with (Err "it does not decrypt: it was changed, or it was encrypted with another key")) (:def (Ok json) (unpack contents) :propagate) - (:def (Ok doc) (parse-device-doc (bytes->string json)) :propagate) + (:def (Ok text) (bytes->string json) :leave-with (Err "the document in it is not UTF-8")) + (:def (Ok doc) (parse-device-doc text) :propagate) ((not (= (.device doc) device)) (Err (str "the header names the device " (uuid->string device) ", and the document names " (uuid->string (.device doc))))) diff --git a/src/title.bjo b/src/title.bjo index e504ada..9d80d98 100644 --- a/src/title.bjo +++ b/src/title.bjo @@ -87,7 +87,7 @@ (let go ((i start)) (if (and (< i end) (name-byte? (cast int (array-ref bytes i)))) (go (+ i 1)) - (bytes->string (ro-span->array (array->ro-span bytes #:from start #:to i)))))) + (bytes->string/lossy (ro-span->array (array->ro-span bytes #:from start #:to i)))))) ;; The charset that a `Content-Type` value names, if it names one. (: (-> string (Option string))) @@ -118,9 +118,9 @@ (def encoding (match charset ((Some name) (match (encoding-named name) ((Some e) e) (None utf-8))) (None utf-8))) - (match (try (bytes->string slice #:encoding encoding) #:catch (System.Exception)) + (match (bytes->string slice #:encoding encoding) ((Ok text) text) - ((Err _) (bytes->string slice #:encoding windows-1252)))) + ((Err _) (bytes->string/lossy slice #:encoding windows-1252)))) ;; The title of the page in the first `n` bytes of `bytes`, as ;; `clean-title` makes it. `None` when there is no whole `` element, diff --git a/tests/title.bjo b/tests/title.bjo index c3bc515..d709d24 100644 --- a/tests/title.bjo +++ b/tests/title.bjo @@ -134,7 +134,7 @@ (if (string-contains? seen "\r\n\r\n") (path-of seen) (match (read-some in) - ((Some bs) (go (str seen (bytes->string bs)))) + ((Some bs) (go (str seen (bytes->string/lossy bs)))) (None (path-of seen)))))) ;; Waits `ms`, or less when the server stops. diff --git a/tests/wayback.bjo b/tests/wayback.bjo index 050086a..b404622 100644 --- a/tests/wayback.bjo +++ b/tests/wayback.bjo @@ -63,7 +63,7 @@ (if (string-contains? seen "\r\n\r\n") (match (string-split-once seen "\r\n") ((Some (Tuple l _)) l) (None seen)) (match (read-some in) - ((Some bs) (go (str seen (bytes->string bs)))) + ((Some bs) (go (str seen (bytes->string/lossy bs)))) (None seen))))) ;; One connection: one request, one answer. The wait ends early when the From fd4c0f8bb019761ea7ac58644fe43d32134f46ef0aa4a85bf50915183709d779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Bj=C3=B6rnstam?= <linus.internet@fastmail.se> Date: Mon, 23 Nov 2026 14:01:18 +0100 Subject: [PATCH 2/2] 0.2.1 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --- manifest.bjodat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.bjodat b/manifest.bjodat index e79d299..eb51818 100644 --- a/manifest.bjodat +++ b/manifest.bjodat @@ -1,6 +1,6 @@ (package (name (bjomarks)) - (version "0.2.0") + (version "0.2.1") (description "Bookmarks in an encrypted store: one file for each device, in any folder that a file syncer or WebDAV shares.") (license "MPL-2.0")