Skip to content

Commit

Permalink
URLs can contain hyphens
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Feb 14, 2025
1 parent 2222c8f commit eda5b56
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export function isMisleadingLink (text, href) {
}
} catch {}

if (/^\s*(\w+\.)+\w+/.test(text)) {
if (/^\s*([\w-]+\.)+\w+/.test(text)) {
if (new URL(hrefUrl.protocol + text).origin !== hrefUrl.origin) {
misleading = true
}
Expand Down
3 changes: 2 additions & 1 deletion lib/url.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ const misleadingLinkCases = [
// if text might be a link to a different origin, it's misleading
['innocent.text', 'https://stacker.news/items/1234', true],
['https://google.com', 'https://bing.com', true],
['www.google.com', 'https://bing.com', true]
['www.google.com', 'https://bing.com', true],
['s-tacker.news', 'https://snacker.news', true]
]

describe('misleading links', () => {
Expand Down

0 comments on commit eda5b56

Please sign in to comment.