Skip to content

Fix canonical-link false positive on root URLs with multi-character TLDs - #30

Merged
fulldecent merged 3 commits into
mainfrom
copilot/fix-canonical-link-false-positive
Aug 19, 2026
Merged

fulldecent merged 3 commits into
mainfrom
copilot/fix-canonical-link-false-positive

Conversation

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

The extension check in CanonicalLinkRule ran against the full URL string, causing root URLs like https://webscore.app to be falsely flagged — .app satisfies \.\w+$ even though the pathname has no extension.

Changes

  • src/rules/CanonicalLinkRule.ts — Parse href with new URL() and test url.pathname instead of the raw href string. Falls back to testing the full href for relative or unparseable URLs.
// Before
if (/\.\w+$/.test(href)) { ... }

// After
let pathname: string
try {
  pathname = new URL(href).pathname
} catch {
  pathname = href
}
if (/\.\w+$/.test(pathname)) { ... }
  • tests/fixtures/CanonicalLinkRule-root-tld.html — New fixture with href="https://webscore.app" (no errors expected).
  • tests/fixtures/required-reports.json — Registers the new fixture with an empty error array.

Co-authored-by: fulldecent <382183+fulldecent@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix canonical link false positive for root URLs with multi-character TLDs Fix canonical-link false positive on root URLs with multi-character TLDs Aug 19, 2026
Copilot AI requested a review from fulldecent August 19, 2026 15:52
@fulldecent

Copy link
Copy Markdown
Owner

@copilot you added a new lockfile and broke sth

that's not how our yarn works

Co-authored-by: fulldecent <382183+fulldecent@users.noreply.github.com>

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot you added a new lockfile and broke sth

that's not how our yarn works

Fixed in the latest commit — removed package-lock.json and restored yarn.lock to match main.

@fulldecent
fulldecent marked this pull request as ready for review August 19, 2026 16:00
Copilot AI lite review requested due to automatic review settings August 19, 2026 16:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a false positive in nice-checkers/canonical-link where root canonical URLs (e.g. https://webscore.app) were incorrectly flagged as “having an extension” by running the extension regex against the full URL string instead of the URL pathname.

Changes:

  • Update CanonicalLinkRule to parse href via new URL() and apply the extension check to url.pathname (fallback to raw href when parsing fails).
  • Add a new fixture covering a root URL with a multi-character TLD and register it with an empty expected error list.
  • Ignore package-lock.json in .gitignore.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/rules/CanonicalLinkRule.ts Uses parsed URL pathname for the extension check to avoid TLD-based false positives.
tests/fixtures/CanonicalLinkRule-root-tld.html Adds regression fixture for root canonical URL with .app.
tests/fixtures/required-reports.json Registers the new fixture with no expected violations.
.gitignore Ignores package-lock.json.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +49 to +53
let pathname: string
try {
pathname = new URL(href).pathname
} catch {
pathname = href
Comment on lines +47 to +55
// Test only the pathname so that multi-character TLDs (.app, .io, .dev) are not flagged.
// Fall back to testing the full href for relative or non-parseable URLs.
let pathname: string
try {
pathname = new URL(href).pathname
} catch {
pathname = href
}
if (/\.\w+$/.test(pathname)) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed at adb7aa8

@fulldecent
fulldecent merged commit da651dd into main Aug 19, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants