mirror of
https://github.com/openai/codex.git
synced 2026-09-04 15:08:45 +00:00
Reject overlapping EOF patch chunks
This commit is contained in:
@@ -27,7 +27,7 @@ pub(crate) fn seek_sequence(
|
||||
return None;
|
||||
}
|
||||
let search_start = if eof && lines.len() >= pattern.len() {
|
||||
lines.len() - pattern.len()
|
||||
(lines.len() - pattern.len()).max(start)
|
||||
} else {
|
||||
start
|
||||
};
|
||||
|
||||
@@ -84,6 +84,26 @@ fn test_apply_patch_cli_applies_multiple_chunks() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_apply_patch_cli_rejects_overlapping_end_of_file_chunks() -> anyhow::Result<()> {
|
||||
let tmp = tempdir()?;
|
||||
let target_path = tmp.path().join("overlapping.txt");
|
||||
let expected_target_path = resolved_under(tmp.path(), "overlapping.txt")?;
|
||||
fs::write(&target_path, "one\n")?;
|
||||
|
||||
let patch = "*** Begin Patch\n*** Update File: overlapping.txt\n@@\n-one\n+first\n@@\n-one\n+second\n*** End of File\n*** End Patch";
|
||||
|
||||
run_apply_patch_in_dir(tmp.path(), patch)?
|
||||
.failure()
|
||||
.stderr(format!(
|
||||
"Failed to find expected lines in {}:\none\n",
|
||||
expected_target_path.display()
|
||||
));
|
||||
|
||||
assert_eq!(fs::read_to_string(target_path)?, "one\n");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_apply_patch_cli_preserves_crlf_from_target_file() -> anyhow::Result<()> {
|
||||
let patch = "*** Begin Patch\n*** Update File: crlf.txt\n@@\n-one\n+uno\n@@\n two\n+\n+between\n three\n*** End Patch";
|
||||
|
||||
Reference in New Issue
Block a user