You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 236cfcb
Browse filesBrowse the repository at this point in the historyBrowse files
@@ -675,6 +683,11 @@ export function replace(content: string, oldString: string, newString: string, r
675
683
if(oldString===newString){
676
684
thrownewError("No changes to apply: oldString and newString are identical.")
677
685
}
686
+
if(oldString===""){
687
+
thrownewError(
688
+
"oldString cannot be empty when editing an existing file. Provide the exact text to replace, or use write for an intentional full-file replacement.",
689
+
)
690
+
}
678
691
679
692
letnotFound=true
680
693
@@ -693,6 +706,11 @@ export function replace(content: string, oldString: string, newString: string, r
693
706
constindex=content.indexOf(search)
694
707
if(index===-1)continue
695
708
notFound=false
709
+
if(isDisproportionateMatch(search,oldString)){
710
+
thrownewError(
711
+
"Refusing replacement because the matched span is much larger than oldString. Re-read the file and provide the full exact oldString for the intended replacement.",
712
+
)
713
+
}
696
714
if(replaceAll){
697
715
returncontent.replaceAll(search,newString)
698
716
}
@@ -709,3 +727,11 @@ export function replace(content: string, oldString: string, newString: string, r
709
727
}
710
728
thrownewError("Found multiple matches for oldString. Provide more surrounding context to make the match unique.")
0 commit comments