Fix canonical-link false positive on root URLs with multi-character TLDs - #30
Merged
Merged
Conversation
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
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>
Contributor
Author
Fixed in the latest commit — removed |
There was a problem hiding this comment.
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
CanonicalLinkRuleto parsehrefvianew URL()and apply the extension check tourl.pathname(fallback to rawhrefwhen 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.jsonin.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)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The extension check in
CanonicalLinkRuleran against the full URL string, causing root URLs likehttps://webscore.appto be falsely flagged —.appsatisfies\.\w+$even though the pathname has no extension.Changes
src/rules/CanonicalLinkRule.ts— Parsehrefwithnew URL()and testurl.pathnameinstead of the rawhrefstring. Falls back to testing the fullhreffor relative or unparseable URLs.tests/fixtures/CanonicalLinkRule-root-tld.html— New fixture withhref="https://webscore.app"(no errors expected).tests/fixtures/required-reports.json— Registers the new fixture with an empty error array.