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'' if url else ""
+ raw_url = r.get("url") or ""
+ url = html.escape(raw_url)
+ if build_readout.is_web_url(raw_url):
+ link = f''
+ 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([]) == ""