fulldecent/html-validate-nice-checkers

bug: canonical-link false positive on root URLs with multi-character TLDs (.app, .io, .dev, etc.)

开放

#28 创建于 2026年6月24日

 (3 条评论) (0 个反应) (0 位负责人)TypeScript (1 个派生)github user discovery
help wanted

仓库指标

星标
 (2 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Bug report

The nice-checkers/canonical-link rule incorrectly flags root canonical URLs when the TLD is multi-character (.app, .io, .dev, .ai, etc.).

Root cause

The extension check runs against the full URL string:

if (/\.\w+$/.test(href)) {

https://webscore.app matches because .app satisfies \.\w+$, even though the pathname has no extension.

Suggested fix

Test only url.pathname instead:

const url = new URL(href)
if (/\.\w+$/.test(url.pathname)) {

https://webscore.app has pathname /, so it passes. https://example.com/page.html has pathname /page.html, so extensions are still caught correctly.

Relates to #26

贡献者指南