fix(news): unwrap CDATA titles at ingest and on /api/news
Excelsior rows store the feed's CDATA wrapper as the title text, including the surrounding whitespace. Strip a whole-title wrapper before insert and again on GET /api/news so existing rows read clean without an UPDATE. Plain titles and real HTML are unchanged.
This commit is contained in:
parent
02a9a5626b
commit
13a4049137
6 changed files with 154 additions and 1 deletions
|
|
@ -176,6 +176,50 @@ def test_api_news_excludes_future_dated_rows(clean_news):
|
|||
assert [a["title"] for a in limited] == ["recent", "recent2"]
|
||||
|
||||
|
||||
@requires_db
|
||||
def test_api_news_unwraps_stored_cdata_title(clean_news):
|
||||
"""Dirty rows are fixed on read. A plain title, and HTML that is not a
|
||||
CDATA wrapper, are returned unchanged. No UPDATE of historical rows.
|
||||
"""
|
||||
stored = "\n <![CDATA[Hello]]> "
|
||||
_seed_article(
|
||||
stored,
|
||||
"https://www.excelsior.com.mx/cdata",
|
||||
"www.excelsior.com.mx",
|
||||
"2026-08-24T18:00:00+00:00",
|
||||
)
|
||||
_seed_article(
|
||||
"Hello",
|
||||
"https://a.example/plain",
|
||||
"a.example",
|
||||
"2026-08-24T17:00:00+00:00",
|
||||
)
|
||||
_seed_article(
|
||||
"<b>Keep</b>",
|
||||
"https://a.example/html",
|
||||
"a.example",
|
||||
"2026-08-24T16:00:00+00:00",
|
||||
)
|
||||
|
||||
body = _get("/api/news").json()
|
||||
by_url = {row["url"]: row["title"] for row in body}
|
||||
assert by_url["https://www.excelsior.com.mx/cdata"] == "Hello"
|
||||
assert by_url["https://a.example/plain"] == "Hello"
|
||||
assert by_url["https://a.example/html"] == "<b>Keep</b>"
|
||||
|
||||
# Read-path only: the stored row stays dirty.
|
||||
async def _stored_title() -> str:
|
||||
conn = await asyncpg.connect(**_conn_kwargs())
|
||||
try:
|
||||
return await conn.fetchval(
|
||||
"SELECT title FROM articles WHERE url = $1",
|
||||
"https://www.excelsior.com.mx/cdata",
|
||||
)
|
||||
finally:
|
||||
await conn.close()
|
||||
|
||||
assert asyncio.run(_stored_title()) == stored
|
||||
|
||||
|
||||
@requires_db
|
||||
def test_api_news_summaries_contract(clean_news):
|
||||
|
|
|
|||
Loading…
Reference in a new issue