Skip to content

Commit 9927d31

Browse files
committed
fix(verify): preserve CRLF when promoting records
1 parent 6612318 commit 9927d31

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎app/verify/promote.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
CROSSREF_CACHE_PATH = STATE_DIR / "crossref_cache.jsonl"
2626

2727
# A top-level, one-key-per-line "verified": false entry (2-space indented).
28-
_VERIFIED_FALSE_RE = re.compile(r'^( )"verified": false(,?)[ \t]*$', re.MULTILINE)
28+
# Permit either common newline convention. With ``re.MULTILINE``, ``$`` sits
29+
# before ``\n`` but after the preceding ``\r`` in CRLF files.
30+
_VERIFIED_FALSE_RE = re.compile(r'^( )"verified": false(,?)[ \t]*(\r?)$', re.MULTILINE)
2931

3032

3133
class PromotionDecision(NamedTuple):
@@ -86,7 +88,7 @@ def flip_verified_text(raw: str) -> str | None:
8688
Returns None (refuse) unless exactly one such token exists, so we never touch
8789
a record that isn't shaped the way we expect.
8890
"""
89-
new, n = _VERIFIED_FALSE_RE.subn(r'\g<1>"verified": true\g<2>', raw)
91+
new, n = _VERIFIED_FALSE_RE.subn(r'\g<1>"verified": true\g<2>\g<3>', raw)
9092
return new if n == 1 else None
9193

9294

‎tests/verify/test_promote_crossref.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ def test_flip_refuses_already_true():
9595
assert promote.flip_verified_text(SEED.replace("false", "true")) is None
9696

9797

98+
def test_flip_preserves_crlf():
99+
crlf_seed = SEED.replace("\n", "\r\n")
100+
out = promote.flip_verified_text(crlf_seed)
101+
assert out is not None
102+
assert ' "verified": true,\r\n' in out
103+
assert "\n" not in out.replace("\r\n", "")
104+
105+
98106
def test_write_back_atomic_lf_preserved():
99107
path = Path(__file__).parent / "_scratch_seed.json"
100108
try:

0 commit comments

Comments
 (0)