fix(agents): validate document formats and trim HTML URLs

This commit is contained in:
4gray committed 2026-09-21 01:45:35 +02:00
1 parent 8f76a2c456
commit a2d1997e29
4 files changed
+36 -3

No files matched your search

+4 -1
View File
@@ -83,7 +83,10 @@ function htmlNavigation(html, inspect = () => {}) {
(node.tagName === 'video' && attribute.name === 'poster')
)
references.push({
target: attribute.value,
target: attribute.value.replace(
/^[\u0000-\u0020]+|[\u0000-\u0020]+$/gu,
''
),
image: !['a', 'area', 'iframe'].includes(node.tagName),
});
if (
+3 -1
View File
@@ -130,7 +130,9 @@ async function packageMentions(rootDir) {
if (
/%[\da-f]{2}/iu.test(token) ||
MARKDOWN_EXTENSION.test(path) ||
/\.(?:txt|json|ya?ml|html?|rst|rest|adoc|asciidoc)$/iu.test(path)
/\.(?:txt|json|ya?ml|html?|rst|rest|adoc|asciidoc|pdf|docx?|odt|rtf|org|tex)$/iu.test(
path
)
)
return false;
if (packages.includes(token)) return true;
@@ -1266,3 +1266,29 @@ for (const extension of ['rst', 'rest', 'adoc', 'asciidoc']) {
);
});
}
for (const extension of ['pdf', 'doc', 'docx', 'odt', 'rtf', 'org', 'tex']) {
test(`document format is not a package exemption: ${extension}`, async (t) => {
assert.ok(
(
await diagnostics(t, {
'package.json': JSON.stringify({
dependencies: { '@angular/core': '*' },
}),
'CLAUDE.md':
'@AGENTS.md\n\nRead @angular/core/docs/guide.' +
extension,
})
).some((message) => message.includes('additional or inline'))
);
});
}
for (const html of [
'<a href=" docs/example.md#repeat ">Guide</a>',
'<iframe src="&#9;docs/example.md&#10;"></iframe>',
'<img src=" docs/example.md ">',
]) {
test(`HTML URL edge whitespace is ignored: ${html}`, async (t) => {
assert.deepEqual(await diagnostics(t, { 'AGENTS.md': html }), []);
});
}