fix(docs-governance): audit UNC markdown links

This commit is contained in:
Seekers2001
2026-09-29 17:41:36 +08:00
parent 71c812686c
commit 4494ffc1e5
3 changed files with 14 additions and 2 deletions
@@ -168,6 +168,7 @@ def markdown_link_targets(text: str) -> list[str]:
def normalize_link_target(raw: str) -> str | None:
target = raw.strip()
is_unc_path = target.startswith("\\\\")
if target.startswith("<"):
closing = target.find(">")
if closing == -1:
@@ -181,7 +182,7 @@ def normalize_link_target(raw: str) -> str | None:
if title:
target = target[: title.start()]
target = unquote(target.split("#", 1)[0].split("?", 1)[0]).replace("\\", "/")
if not target or target.startswith("//"):
if not target or (target.startswith("//") and not is_unc_path):
return None
if EXTERNAL_URI_RE.match(target):
return None
@@ -168,6 +168,7 @@ def markdown_link_targets(text: str) -> list[str]:
def normalize_link_target(raw: str) -> str | None:
target = raw.strip()
is_unc_path = target.startswith("\\\\")
if target.startswith("<"):
closing = target.find(">")
if closing == -1:
@@ -181,7 +182,7 @@ def normalize_link_target(raw: str) -> str | None:
if title:
target = target[: title.start()]
target = unquote(target.split("#", 1)[0].split("?", 1)[0]).replace("\\", "/")
if not target or target.startswith("//"):
if not target or (target.startswith("//") and not is_unc_path):
return None
if EXTERNAL_URI_RE.match(target):
return None
+10
View File
@@ -128,6 +128,16 @@ def test_artifact_scope_ignores_protocol_relative_external_links(project: Path)
assert result.returncode == 0, result.stdout
def test_artifact_scope_checks_unc_style_links(project: Path) -> None:
(project / "guide.md").write_text(
"[missing](\\\\server\\share\\missing.md)\n", encoding="utf-8"
)
result = run_audit(project, "artifacts")
assert result.returncode == 1
assert "Broken Markdown link" in result.stdout
assert "//server/share/missing.md" in result.stdout
def test_artifact_scope_ignores_external_uri_schemes_case_insensitively(
project: Path,
) -> None: