Repository navigation
feat(ts): translate lossy and chunked UTF-8 decoding - #537
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
marked this pull request as ready for review
November 3, 2026 18:50
|
This run was cancelled before it finished. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 54 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. CodeRabbit Verify
|
This was referenced Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
rust2-ts refused
String::from_utf8_lossy(found by #528), and with it the rest of std's stable lossy and chunked UTF-8 decoding. No quest covered it; the maintainer plans all of std.Survey of the family on main:
str::from_utf8,String::from_utf8,Utf8Error::valid_up_toanderror_len, andDebug/Display/Clone/==of both errors already translated. Refused were:String::from_utf8_lossy;<[u8]>::utf8_chunksand itsUtf8Chunks(Debug,Clone);Utf8Chunk(the type,valid,invalid,Debug,Clone,==);FromUtf8Error::as_bytes,into_bytes,utf8_error;str::from_utf8_uncheckedandString::from_utf8_unchecked;String::into_bytesandVec::<u8>::fromaStringor&str.Approach
from_utf8_lossyisrt.stringFromUtf8Lossy: a non-fatalTextDecoderwithignoreBOM. WHATWG's UTF-8 decoder writes one U+FFFD per maximal invalid subsequence, the same rule std'sUtf8Chunksfollows; the differential test confirms it. ItsCow<str>is the text, as everyCow<str>already is.utf8_chunksisrt.byteSliceUtf8Chunks, anIter<rt.Utf8Chunk>that splits where the existing UTF-8 check (nowrt.utf8Check, returningundefinedfor valid input) fails. A sequence cut off by the end of the input is invalid up to the end, as in std.DebugwritesUtf8Chunks { source: "..." }, with each invalid byte as\xNN.Utf8Chunkis{ valid, invalid }. Its derived==lowers from std's MIR, as std's errors' do (Std::erroris renamedStd::recordto cover it).Clonereturns the value, andDebugmatches std's derived output.FromUtf8Error's accessors read itsbytesanderror.from_utf8_unchecked(ofstrorString) decodes with the lossy decoder. By contract the input is valid, so the result is exactly the text.String::into_bytesandVec::<u8>::froma string arert.stringIntoBytes.Tests:
lang/utf8gainsutf8::lossy. It runs on random raw bytes, on bytes from an alphabet of UTF-8 boundary bytes, and on hand-picked inputs: a BOM, truncated sequences (at the end and cut by another byte), overlongs, encoded surrogates, bytes above F4, empty input, and valid multi-byte text. From every offset it compares the lossy text, every chunk'svalid/invalid/Debug/==, the iterator'sDebugand clones as it advances, and the unchecked and byte conversions. It also checksFromUtf8Error's accessors. Mutation check: making a truncated chunk 1 byte long fails 10 of 361 cases.Not covered, because each is a recorded design choice: the
BorrowedvsOwnedvariant of the returnedCow<str>can't be observed. ACow<str>is a JS string, and matching its variant is refused with a span (reject/src/strs.rs, #105).str::from_utf8_mutstays refused as the README documents, since no JS string is written in place.Impact
rt.stringFromUtf8Lossy,rt.byteSliceUtf8Chunks,rt.Utf8Chunk,rt.fmtUtf8Chunks,rt.fmtUtf8ChunkDebug,rt.stringIntoBytes,rt.utf8Check. No breaking change.Alternatives
Utf8Chunks: same output, but slower than the engine's native decoder, which already follows the same replacement rule.Cow<str>a variant so the lossy result'sBorrowed/Ownedcan be observed: that changes everyCow<str>, so it belongs in a quest of its own.Follow-ups
/quest-plan: matching aCow<str>'s variants, which is stable std that is still refused (see Not covered above).Review
Codex (gpt-6.1-sol, medium effort) via
quest review, round 1, head7a88ae3346ec24cc87928e2e5c687b7c71df2eba: no findings. Since then only a conflict-free merge ofmain.🤖 Generated with Claude Code