Skip to content

Url detected by the library but considered as invalid by URL native module #506

@Apokalypt

Description

@Apokalypt

I use the library to detect, in messages, URLs used to scam people. However, today, the detection failed on a message due to an invalid library detection preventing a parse by nodejs' native URL library

Code

function findURLs(text: string): URL[] {
    return linkify.find(text, "url")
        .map( l => new URL(l.href) );
}

const messageWithTwoUrls = "[https://store.steampowered.com](https://u.com/aig)"
const res = findURLs(messageWithTwoUrls) // <- error thrown by new URL

Url detected

[{
  "type": "url",
  "value": "https://store.steampowered.com](https://u.com/aig)",
  "isLink": true,
  "href": "https://store.steampowered.com](https://u.com/aig)"
}]

Expected

[{
  "type": "url",
  "value": "https://store.steampowered.com",
  "isLink": true,
  "href": "https://store.steampowered.com"
},{
  "type": "url",
  "value": "https://u.com/aig",
  "isLink": true,
  "href": "https://u.com/aig"
}]

Metadata

Metadata

Assignees

Labels

bugparsingRelated to string parsing

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions