mirror of
https://github.com/affaan-m/ECC.git
synced 2026-12-04 06:01:50 +09:00
fix(docs-governance): look for a blanked comment in the link destination, not its title
A title may hold comment-shaped text, as in [x](missing.md "<!-- c -->"). The filter for blanked comments looked at the whole target, title included, so it dropped that link and its broken destination went unreported. The filter now strips the title first, with the same pattern normalize_link_target uses, which moves to LINK_TITLE_RE.
This commit is contained in:
5 files changed
+59
-30
No files matched your search
@@ -18,6 +18,9 @@ REFERENCE_DEFINITION_RE = re.compile(
|
||||
REFERENCE_USAGE_RE = re.compile(
|
||||
r"(?<![\\])(?:\\\\)*\[(?P<text>[^\]\n]+)\](?:\[(?P<label>[^\]\n]*)\])?"
|
||||
)
|
||||
LINK_TITLE_RE = re.compile(
|
||||
r'\s+(?:"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'|\([^()]*\))\s*$'
|
||||
)
|
||||
EXTERNAL_URI_RE = re.compile(
|
||||
r"^(?:[A-Za-z][A-Za-z0-9+.-]*://|(?:data|doi|geo|irc|magnet|mailto|news|sms|tel|urn):)",
|
||||
re.IGNORECASE,
|
||||
@@ -77,7 +80,11 @@ def without_inline_code_and_html_comments(text: str) -> str:
|
||||
cursor = 0
|
||||
comments_can_close = True
|
||||
while cursor < len(text):
|
||||
if comments_can_close and text.startswith("<!--", cursor) and not _is_escaped(text, cursor):
|
||||
if (
|
||||
comments_can_close
|
||||
and text.startswith("<!--", cursor)
|
||||
and not _is_escaped(text, cursor)
|
||||
):
|
||||
closing = text.find("-->", cursor + 2)
|
||||
if closing != -1:
|
||||
output.extend(
|
||||
@@ -210,8 +217,14 @@ def reference_link_targets(text: str) -> list[str]:
|
||||
def markdown_link_targets(text: str) -> list[str]:
|
||||
text = without_inline_code_and_html_comments(without_fenced_code(text))
|
||||
targets = inline_link_targets(text) + reference_link_targets(text)
|
||||
# -- a destination made of a blanked comment is no link --
|
||||
return [target for target in targets if "\0" not in target]
|
||||
# -- a destination made of a blanked comment is no link; a title may hold one --
|
||||
return [target for target in targets if "\0" not in _without_title(target)]
|
||||
|
||||
|
||||
def _without_title(raw: str) -> str:
|
||||
target = raw.strip()
|
||||
title = None if target.startswith("<") else LINK_TITLE_RE.search(target)
|
||||
return target[: title.start()] if title else target
|
||||
|
||||
|
||||
def normalize_link_target(raw: str) -> str | None:
|
||||
@@ -223,12 +236,7 @@ def normalize_link_target(raw: str) -> str | None:
|
||||
return None
|
||||
target = target[1:closing]
|
||||
else:
|
||||
title = re.search(
|
||||
r'\s+(?:"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'|\([^()]*\))\s*$',
|
||||
target,
|
||||
)
|
||||
if title:
|
||||
target = target[: title.start()]
|
||||
target = _without_title(target)
|
||||
# Unescape supported Markdown punctuation before Windows path separators.
|
||||
target = re.sub(r"\\([()\[\]'])", r"\1", target)
|
||||
target = unquote(target.split("#", 1)[0].split("?", 1)[0]).replace("\\", "/")
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"id": "hand-seeded",
|
||||
"source": "manual-curation-pending-regeneration"
|
||||
},
|
||||
"registryDigest": "77c061805c8948d8e0b7929816fcfedd4f30136f2c0c3af6d23db92cd3f03379",
|
||||
"registryDigest": "9d5aadcd27e353dfb00ca2d9312d62a5967203bf7fd0b3ccf2a60d7022ada739",
|
||||
"schemaVersion": 1,
|
||||
"triggers": {
|
||||
"skill:agent-runtime-gateway-smoke-test": [
|
||||
|
||||
@@ -18,6 +18,9 @@ REFERENCE_DEFINITION_RE = re.compile(
|
||||
REFERENCE_USAGE_RE = re.compile(
|
||||
r"(?<![\\])(?:\\\\)*\[(?P<text>[^\]\n]+)\](?:\[(?P<label>[^\]\n]*)\])?"
|
||||
)
|
||||
LINK_TITLE_RE = re.compile(
|
||||
r'\s+(?:"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'|\([^()]*\))\s*$'
|
||||
)
|
||||
EXTERNAL_URI_RE = re.compile(
|
||||
r"^(?:[A-Za-z][A-Za-z0-9+.-]*://|(?:data|doi|geo|irc|magnet|mailto|news|sms|tel|urn):)",
|
||||
re.IGNORECASE,
|
||||
@@ -77,7 +80,11 @@ def without_inline_code_and_html_comments(text: str) -> str:
|
||||
cursor = 0
|
||||
comments_can_close = True
|
||||
while cursor < len(text):
|
||||
if comments_can_close and text.startswith("<!--", cursor) and not _is_escaped(text, cursor):
|
||||
if (
|
||||
comments_can_close
|
||||
and text.startswith("<!--", cursor)
|
||||
and not _is_escaped(text, cursor)
|
||||
):
|
||||
closing = text.find("-->", cursor + 2)
|
||||
if closing != -1:
|
||||
output.extend(
|
||||
@@ -210,8 +217,14 @@ def reference_link_targets(text: str) -> list[str]:
|
||||
def markdown_link_targets(text: str) -> list[str]:
|
||||
text = without_inline_code_and_html_comments(without_fenced_code(text))
|
||||
targets = inline_link_targets(text) + reference_link_targets(text)
|
||||
# -- a destination made of a blanked comment is no link --
|
||||
return [target for target in targets if "\0" not in target]
|
||||
# -- a destination made of a blanked comment is no link; a title may hold one --
|
||||
return [target for target in targets if "\0" not in _without_title(target)]
|
||||
|
||||
|
||||
def _without_title(raw: str) -> str:
|
||||
target = raw.strip()
|
||||
title = None if target.startswith("<") else LINK_TITLE_RE.search(target)
|
||||
return target[: title.start()] if title else target
|
||||
|
||||
|
||||
def normalize_link_target(raw: str) -> str | None:
|
||||
@@ -223,12 +236,7 @@ def normalize_link_target(raw: str) -> str | None:
|
||||
return None
|
||||
target = target[1:closing]
|
||||
else:
|
||||
title = re.search(
|
||||
r'\s+(?:"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'|\([^()]*\))\s*$',
|
||||
target,
|
||||
)
|
||||
if title:
|
||||
target = target[: title.start()]
|
||||
target = _without_title(target)
|
||||
# Unescape supported Markdown punctuation before Windows path separators.
|
||||
target = re.sub(r"\\([()\[\]'])", r"\1", target)
|
||||
target = unquote(target.split("#", 1)[0].split("?", 1)[0]).replace("\\", "/")
|
||||
|
||||
@@ -18,6 +18,9 @@ REFERENCE_DEFINITION_RE = re.compile(
|
||||
REFERENCE_USAGE_RE = re.compile(
|
||||
r"(?<![\\])(?:\\\\)*\[(?P<text>[^\]\n]+)\](?:\[(?P<label>[^\]\n]*)\])?"
|
||||
)
|
||||
LINK_TITLE_RE = re.compile(
|
||||
r'\s+(?:"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'|\([^()]*\))\s*$'
|
||||
)
|
||||
EXTERNAL_URI_RE = re.compile(
|
||||
r"^(?:[A-Za-z][A-Za-z0-9+.-]*://|(?:data|doi|geo|irc|magnet|mailto|news|sms|tel|urn):)",
|
||||
re.IGNORECASE,
|
||||
@@ -77,7 +80,11 @@ def without_inline_code_and_html_comments(text: str) -> str:
|
||||
cursor = 0
|
||||
comments_can_close = True
|
||||
while cursor < len(text):
|
||||
if comments_can_close and text.startswith("<!--", cursor) and not _is_escaped(text, cursor):
|
||||
if (
|
||||
comments_can_close
|
||||
and text.startswith("<!--", cursor)
|
||||
and not _is_escaped(text, cursor)
|
||||
):
|
||||
closing = text.find("-->", cursor + 2)
|
||||
if closing != -1:
|
||||
output.extend(
|
||||
@@ -210,8 +217,14 @@ def reference_link_targets(text: str) -> list[str]:
|
||||
def markdown_link_targets(text: str) -> list[str]:
|
||||
text = without_inline_code_and_html_comments(without_fenced_code(text))
|
||||
targets = inline_link_targets(text) + reference_link_targets(text)
|
||||
# -- a destination made of a blanked comment is no link --
|
||||
return [target for target in targets if "\0" not in target]
|
||||
# -- a destination made of a blanked comment is no link; a title may hold one --
|
||||
return [target for target in targets if "\0" not in _without_title(target)]
|
||||
|
||||
|
||||
def _without_title(raw: str) -> str:
|
||||
target = raw.strip()
|
||||
title = None if target.startswith("<") else LINK_TITLE_RE.search(target)
|
||||
return target[: title.start()] if title else target
|
||||
|
||||
|
||||
def normalize_link_target(raw: str) -> str | None:
|
||||
@@ -223,12 +236,7 @@ def normalize_link_target(raw: str) -> str | None:
|
||||
return None
|
||||
target = target[1:closing]
|
||||
else:
|
||||
title = re.search(
|
||||
r'\s+(?:"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'|\([^()]*\))\s*$',
|
||||
target,
|
||||
)
|
||||
if title:
|
||||
target = target[: title.start()]
|
||||
target = _without_title(target)
|
||||
# Unescape supported Markdown punctuation before Windows path separators.
|
||||
target = re.sub(r"\\([()\[\]'])", r"\1", target)
|
||||
target = unquote(target.split("#", 1)[0].split("?", 1)[0]).replace("\\", "/")
|
||||
|
||||
@@ -289,6 +289,8 @@ def test_artifact_scope_reads_html_comments_as_commonmark_does(project: Path) ->
|
||||
# -- a comment where a destination must begin does not make a definition --
|
||||
"[foo]: <!-- note --> missing-definition.md\n\n[foo]\n\n"
|
||||
"[bar]: <!-- only a comment -->\n\n[bar]\n\n"
|
||||
# -- a title may hold comment-shaped text; the destination is still audited --
|
||||
'[titled](missing-titled.md "<!-- c -->")\n\n'
|
||||
# -- a fence line inside a comment block is comment text; the fence after it is real --
|
||||
"<!--\n```\n-->\n```\n[fenced](missing-fenced.md)\n```\n",
|
||||
encoding="utf-8",
|
||||
@@ -296,10 +298,13 @@ def test_artifact_scope_reads_html_comments_as_commonmark_does(project: Path) ->
|
||||
result = run_audit(project, "artifacts")
|
||||
assert result.returncode == 1
|
||||
assert "Broken Markdown link: 'guide.md' -> 'missing-escaped.md'" in result.stdout
|
||||
assert "Broken Markdown link: 'guide.md' -> 'missing-after-code.md'" in result.stdout
|
||||
assert (
|
||||
"Broken Markdown link: 'guide.md' -> 'missing-after-code.md'" in result.stdout
|
||||
)
|
||||
assert "missing-definition.md" not in result.stdout
|
||||
assert "Broken Markdown link: 'guide.md' -> 'missing-titled.md'" in result.stdout
|
||||
assert "missing-fenced.md" not in result.stdout
|
||||
assert result.stdout.count("Broken Markdown link") == 2, result.stdout
|
||||
assert result.stdout.count("Broken Markdown link") == 3, result.stdout
|
||||
|
||||
|
||||
def test_artifact_scope_ignores_title_with_escaped_quotes(project: Path) -> None:
|
||||
|
||||
Reference in new issue
Block a user