fix(extract): guard remember fast-path against UTF-8 char-boundary panic#641
Closed
e11734937-beep wants to merge 1 commit into
Closed
fix(extract): guard remember fast-path against UTF-8 char-boundary panic#641e11734937-beep wants to merge 1 commit into
e11734937-beep wants to merge 1 commit into
Conversation
extract_facts sliced trimmed[..8] (and extract_remember sliced text[..PREFIX.len()]) behind only a byte-length check, so an utterance whose 8th byte fell inside a multi-byte UTF-8 char panicked (byte index 8 is not a char boundary). Use str::get(..n), which returns None instead of panicking on a non-char-boundary, so non-ASCII input simply does not match the fast-path. Adds a regression test with CJK/emoji inputs whose byte 8 is interior. Closes GeniePod#634
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.
Fixes #634.
extract_factsslicedtrimmed[..8](andextract_rememberslicedtext[..PREFIX.len()]) behind only a byte-length check, so any utterance whose 8th byte fell inside a multi-byte UTF-8 character panicked with "byte index 8 is not a char boundary".Three sites had this pattern:
!needs_extract_facts_lowerfast-path,extract_facts"remember" branch,extract_rememberprefix check.Each now uses
str::get(..n), which returnsNonewhen the index is out of range or not a char boundary — so non-ASCII input simply doesn't match the fast-path instead of panicking. ASCII "remember" behaviour is unchanged.Regression tests added:
non_ascii_input_does_not_panic— CJK / mixed / emoji inputs whose interior byte 8 previously panicked no longer do, and don't spuriously match.remember_still_matches_with_non_ascii_payload— a genuineRemember 日本語 …request is still captured with its payload preserved.