Commit 7a753885
7a753885870fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · +1 added · ~1 modified
Description
Save last_pos in StringScanner#check for correct unscan
CRuby's check matches at the current position without advancing, but it
still records the pre-match position, so a following unscan rewinds to
just before the check (and pre_match/post_match reflect the check
match). Spinel's check skipped sc->last_pos = sc->pos, so after a
scan + check an unscan jumped back to the position saved by the earlier
scan, often the start of the string.
Set last_pos on a successful check match, mirroring scan. A failed check
leaves last_pos untouched, matching CRuby (where unscan after a failed
match raises rather than rewinding).
Fixes #1266
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 7a753885870f
- Parent
- 831c2911d34e
lib/sp_strscan.cmodifiedView file
return sp_ext_str_empty(); } char *m = sc_substr(sc->source, sc->pos, mlen); sc->last_pos = sc->pos; sc->matched = m; sc->matched_p = 1; return m;test/string_scanner_check_unscan.rbaddedView file
Loading diff…