Skip to content

Commit 9fd671e

Browse files
committed
fix(verify): preserve CRLF when promoting records
1 parent db18079 commit 9fd671e

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):
@@ -93,7 +95,7 @@ def flip_verified_text(raw: str) -> str | None:
9395
Returns None (refuse) unless exactly one such token exists, so we never touch
9496
a record that isn't shaped the way we expect.
9597
"""
96-
new, n = _VERIFIED_FALSE_RE.subn(r'\g<1>"verified": true\g<2>', raw)
98+
new, n = _VERIFIED_FALSE_RE.subn(r'\g<1>"verified": true\g<2>\g<3>', raw)
9799
return new if n == 1 else None
98100

99101

‎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)