From 2c007837c255a4f689184174c93ca92241371370 Mon Sep 17 00:00:00 2001 From: Socialpranker <273312799+Socialpranker@users.noreply.github.com> Date: Tue, 17 Nov 2026 06:05:20 +0100 Subject: [PATCH] =?UTF-8?q?fix(report):=20=D1=81=D1=81=D1=8B=D0=BB=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=20=D0=B8=D1=81=D1=82=D0=BE=D1=87=D0=BD?= =?UTF-8?q?=D0=B8=D0=BA=20=D0=B2=20=D1=82=D0=B5=D1=85=D0=BE=D1=82=D1=87?= =?UTF-8?q?=D1=91=D1=82=D0=B5=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20http(s)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sources_appendix экранировал URL, но схему не проверял, поэтому javascript: из источника становился кликабельной ссылкой. Проверка схемы вынесена в build_readout.is_web_url и используется в обоих отчётах; чужой адрес показывается текстом без ссылки. --- scripts/build_readout.py | 13 ++++++++----- scripts/build_report.py | 8 ++++++-- tests/test_report_export.py | 11 +++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/scripts/build_readout.py b/scripts/build_readout.py index 85de7ab..d1ce2b5 100644 --- a/scripts/build_readout.py +++ b/scripts/build_readout.py @@ -472,6 +472,12 @@ def credibility_word(value: str) -> str: return "высокая" if v >= 4 else "средняя" if v == 3 else "низкая" +def is_web_url(url: str) -> bool: + """Source URLs come from fetched pages; any other scheme (javascript:, data:) would run on click.""" + parsed = urlparse(url) + return parsed.scheme in {"http", "https"} and bool(parsed.netloc) + + def source_index(rows: list[dict], used_by: dict[str, list[int]]) -> str: live = [r for r in rows if (r.get("used") or "Y") != "N"] if not live: @@ -502,11 +508,8 @@ def source_index(rows: list[dict], used_by: dict[str, list[int]]) -> str: ) ) url = r.get("url") or "" - parsed = urlparse(url) - host = parsed.netloc.removeprefix("www.") - # URLs come from fetched pages; any other scheme (javascript:, data:) would run on click. - linkable = parsed.scheme in {"http", "https"} and host - link = f' · {html.escape(host)}' if linkable else "" + host = urlparse(url).netloc.removeprefix("www.") + link = f' · {html.escape(host)}' if is_web_url(url) else "" num = int(sid[1:]) if re.fullmatch(r"s\d+", sid) else html.escape(sid) out.append( f'
{num}
{title}
{" · ".join(bits)}{link}
' diff --git a/scripts/build_report.py b/scripts/build_report.py index 18836ec..e344706 100644 --- a/scripts/build_report.py +++ b/scripts/build_report.py @@ -230,8 +230,12 @@ def sources_appendix(rows: list[dict]) -> str: ], ) ) - url = html.escape(r.get("url") or "") - link = f'
{url}
' if url else "" + raw_url = r.get("url") or "" + url = html.escape(raw_url) + if build_readout.is_web_url(raw_url): + link = f'
{url}
' + else: + link = f'
{url}
' if url else "" out.append(f'
[{sid}]
') out.append(f'
{title}
{meta}
{link}
') out += ["", ""] diff --git a/tests/test_report_export.py b/tests/test_report_export.py index 89e1935..6241881 100644 --- a/tests/test_report_export.py +++ b/tests/test_report_export.py @@ -308,6 +308,17 @@ def test_sources_appendix_lists_every_row(): assert "Источник A" in out and "Primary" in out +def test_sources_appendix_links_only_http_urls(): + rows = [ + {"id": "s01", "url": "javascript:alert(1)", "title": "x"}, + {"id": "s02", "url": "https://ok.example/p", "title": "y"}, + ] + out = br.sources_appendix(rows) + assert 'href="javascript:' not in out + assert "javascript:alert(1)" in out # адрес виден текстом, но не кликается + assert 'href="https://ok.example/p"' in out + + def test_empty_sources_produce_no_appendix(): assert br.sources_appendix([]) == ""