-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test()
and find()
do not find the same strings as valid/invalid links
#472
Comments
Hi @rfgamaral, thanks for the report. The output of You can see this this clearly when you run linkify.tokenize("1.nf3").map(token => token.toObject()) Output: [
{
"type": "url",
"value": "1.nf",
"isLink": true,
"href": "http://1.nf",
"start": 0,
"end": 4
},
{
"type": "text",
"value": "3",
"isLink": false,
"href": "3",
"start": 4,
"end": 5
}
]
Hope that helps |
@nfrasser Thank you for the quick reply, however, this creates a problem on our side, that I'm not exactly sure how to fix. This issue was first reported to one of our products in the context of a rich-text editor. A user typed Do you have any suggestions on how to approach "fixing" or improving this behaviour based on the rationale explained above? The auto linking mechanism in Tiptap provides a |
@rfgamaral thanks for the additional explanation, I can definitely empathize with the expected behaviour here. Unfortunately I don't have an easy fix for this. Linkify's parser implementation has to support cases where there are no spaces around the URL. A fix for this would likely mean breaking other valid cases. It comes down to the inherent ambiguity of mixing plain-text with machine-readable strings. Related issues to showcase the kinds of challenges I have to account for:
If you haven't already, I would suggest reporting this issue with Tiptap. Perhaps they can tweak their editor's implementation to avoid detecting links in the string immediately before the Another potential option: Try linkify v3 instead of v4, which has a slightly different parsing implementation. The drawback there is that since it's an older version, it might have other bugs or missing features. Edit: Typo fix |
I'm prepared to tackle this myself and open a PR against Tiptap, I'm just trying to understand what would be the best solution.
I think that might effectively disable auto-linking for things like
My only concern is that docs mention that However, this feels like the type of link validation that I would expect to exist in a rich-text editor with auto-linking functionality. So, to summarize, I could open a PR in Tiptap to use |
FYI, I ended up opening a PR on Tiptap replacing |
Similar situation here:
returns as false, whereas
|
Hello there 👋.
Going straight to the point:
find()
Output:
test()
Output:
false
I understand that Linkify is not 100% spec compliant, but shouldn't
test()
andfind()
return the same output? More importantly,linkify.find('1.nf3')
should return[]
because.nf3
is not a valid TLD while.nf
is (ref).Is this a bug, or is this somehow intended?
The text was updated successfully, but these errors were encountered: