Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/verify/promote.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
CROSSREF_CACHE_PATH = STATE_DIR / "crossref_cache.jsonl"

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


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


Expand Down
8 changes: 8 additions & 0 deletions tests/verify/test_promote_crossref.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ def test_flip_refuses_already_true():
assert promote.flip_verified_text(SEED.replace("false", "true")) is None


def test_flip_preserves_crlf():
crlf_seed = SEED.replace("\n", "\r\n")
out = promote.flip_verified_text(crlf_seed)
assert out is not None
assert ' "verified": true,\r\n' in out
assert "\n" not in out.replace("\r\n", "")


def test_write_back_atomic_lf_preserved():
path = Path(__file__).parent / "_scratch_seed.json"
try:
Expand Down
Loading