mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-14 14:12:44 +00:00
fix(tools): stop _strategy_exact emitting overlapping matches (#56211)
_strategy_exact advanced its scan cursor by pos+1 instead of pos+len(pattern), so self-overlapping patterns (e.g. "aa" in "aaaa") matched at overlapping offsets. _apply_replacements works in reverse order, so the second replacement operated on already-modified content using stale offsets — corrupting the file and reporting the wrong count under replace_all=True. Advancing by len(pattern) matches str.replace() semantics.
This commit is contained in:
parent
ea533e7f41
commit
d57a4c197c
2 changed files with 39 additions and 1 deletions
|
|
@ -349,7 +349,12 @@ def _strategy_exact(content: str, pattern: str) -> List[Tuple[int, int]]:
|
|||
if pos == -1:
|
||||
break
|
||||
matches.append((pos, pos + len(pattern)))
|
||||
start = pos + 1
|
||||
# Advance past the whole match, not just one char, so self-overlapping
|
||||
# patterns (e.g. "aa" in "aaaa") produce non-overlapping spans matching
|
||||
# str.replace() semantics. Advancing by 1 yielded overlapping matches
|
||||
# that corrupt the file under replace_all=True (reverse-order apply on
|
||||
# stale offsets).
|
||||
start = pos + len(pattern)
|
||||
return matches
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue