Skip to content

Fix atEnd edge case - #169

Merged
svenvc merged 2 commits into
svenvc:masterfrom
panalcloud:fix-bom-atend
Nov 13, 2026
Merged

svenvc merged 2 commits into
svenvc:masterfrom
panalcloud:fix-bom-atend

Conversation

@lopezca

@lopezca lopezca commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Hi @svenvc, here is a fix for a problem that breaks STON with that mythical unicode point. please take a look.

the llm's summary:

STON's reader loops on [ readStream atEnd not and: [ readStream peek isSeparator ] ] (and on isDigit and similar while parsing numbers and symbols), and it reports parse errors at readStream position. Both broke on a ZnCharacterReadStream. ZnEncodedReadStream>>#atEnd used to check only whether bytes remained, so when the input ended in a byte order mark that the decoder ignores, atEnd answered false while peek answered nil. STON then sent nil isSeparator and failed: STON fromStream: on '[1,2]' followed by U+FEFF raised a MessageNotUnderstood instead of answering #(1 2). On fix-bom-atend, atEnd decodes one element ahead into peeked, so it answers true when only an ignored mark is left, and a peek after atEnd answers false always yields a character. Separately, position used to subtract one byte for a peeked character whatever its size, so after peeking a multi-byte character STON reported the wrong error position (5 instead of 3 for '[1,€]'). It now subtracts the peeked character's actual encoded size, and the UTF-8 byte count for U+FFFF is corrected to 3.

- atEnd before an ignored byte order mark that ends the input
- position after peek of a multi-byte character
- UTF-8 encoded byte count and overlong form of U+FFFF
…U+FFFF

- atEnd decodes one element ahead, without sending peek
- position subtracts the encoded size of the peeked element
- UTF-8 counts U+FFFF as 3 bytes and rejects its 4-byte form
- upToEnd temporary no longer shadows the encoder variable
@svenvc

svenvc commented Nov 13, 2026

Copy link
Copy Markdown
Owner

OK, good. Thx.

@svenvc
svenvc merged commit 89fc898 into svenvc:master Nov 13, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants