File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525CROSSREF_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
3133class 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
Original file line number Diff line number Diff 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+
98106def test_write_back_atomic_lf_preserved ():
99107 path = Path (__file__ ).parent / "_scratch_seed.json"
100108 try :
You can’t perform that action at this time.
0 commit comments