From 4694b6b68da7c6a8672eed4cd504a298a837c0e6 Mon Sep 17 00:00:00 2001 From: Sankalp-Mittal Date: Tue, 6 Oct 2026 11:41:53 +0000 Subject: [PATCH 1/2] acc: make update_file.py replace bytes to preserve line endings update_file.py opened the file in text mode. On Windows that reads CRLF as LF and writes every LF back as CRLF, so an LF file (e.g. *.txt, which .gitattributes pins to eol=lf, or files written by printf/envsubst) came back with CRLF line endings. That changes the file's hash and upload payload beyond the intended edit. Read and write bytes instead. When the file already uses CRLF, convert "\n" in OLD/NEW to "\r\n" so multi-line replacements keep matching on Windows checkouts with core.autocrlf=true. Co-authored-by: Isaac --- acceptance/bin/update_file.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/acceptance/bin/update_file.py b/acceptance/bin/update_file.py index ef643239533..5b7b9e58eb0 100755 --- a/acceptance/bin/update_file.py +++ b/acceptance/bin/update_file.py @@ -5,6 +5,10 @@ Replace all strings OLD with NEW in FILENAME. If OLD is not found in FILENAME, the script reports error. + +The file is read and written as bytes so that only the matched bytes change. +Text mode on Windows rewrites every line ending as CRLF, which changes the +file's content hash and upload payload. """ import sys @@ -20,9 +24,19 @@ # call update_file.py on that file. assert filename != "output.txt" -data = open(filename).read() -newdata = data.replace(old, new) +with open(filename, "rb") as fobj: + data = fobj.read() + +old_bytes = old.encode() +new_bytes = new.encode() + +# Match the file's line endings so multi-line OLD/NEW work on CRLF checkouts. +if b"\r\n" in data: + old_bytes = old_bytes.replace(b"\n", b"\r\n") + new_bytes = new_bytes.replace(b"\n", b"\r\n") + +newdata = data.replace(old_bytes, new_bytes) if newdata == data: - sys.exit(f"{old=} not found in {filename=}\n{data}") -with open(filename, "w") as fobj: + sys.exit(f"{old=} not found in {filename=}\n{data.decode(errors='replace')}") +with open(filename, "wb") as fobj: fobj.write(newdata) From f3544216c4c9b2456758e4cab209407a937a1ec3 Mon Sep 17 00:00:00 2001 From: Sankalp-Mittal Date: Tue, 6 Oct 2026 12:59:27 +0000 Subject: [PATCH 2/2] acc: don't double CR when OLD/NEW already contain CRLF On a CRLF file, "\n" in OLD/NEW was converted to "\r\n" unconditionally, so an argument that already had "\r\n" became "\r\r\n". Normalize to "\n" first, then convert. Co-authored-by: Isaac --- acceptance/bin/update_file.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/acceptance/bin/update_file.py b/acceptance/bin/update_file.py index 5b7b9e58eb0..8a69d5f5fef 100755 --- a/acceptance/bin/update_file.py +++ b/acceptance/bin/update_file.py @@ -32,8 +32,8 @@ # Match the file's line endings so multi-line OLD/NEW work on CRLF checkouts. if b"\r\n" in data: - old_bytes = old_bytes.replace(b"\n", b"\r\n") - new_bytes = new_bytes.replace(b"\n", b"\r\n") + old_bytes = old_bytes.replace(b"\r\n", b"\n").replace(b"\n", b"\r\n") + new_bytes = new_bytes.replace(b"\r\n", b"\n").replace(b"\n", b"\r\n") newdata = data.replace(old_bytes, new_bytes) if newdata == data: