fix(extension-link): Avoid auto-linking partial text for invalid TLDs #4865
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.
Please describe your changes
This PR implements better autolink validation to ensure that only complete and valid text is hyperlinked, preventing cases where a valid top-level domain (TLD) is immediately followed by an invalid character, like a number.
For instance, with the
find
method from Linkify, typing the textexample.com1
would result inexample.com
being linked and the trailing1
left as plain text:This behaviour is a bit unexpected, and this PR implements a more comprehensive validation on the input text.
How did you accomplish your changes
With the
tokenize
method instead offind
, which allows us to perform a more comprehensive validation on the input text.Note
The
find
method usestokenize
internally, but it does a much simpler validation.How have you tested your changes
Used the
Link
extension demo to test multiple link formats to make sure that autolinking still worked as expected.How can we verify your changes
Use the
Link
extension demo as I did.