Skip to content
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

Fix: Autolink plugin URL recognition failures #5275

Conversation

disalechinmay
Copy link
Contributor

This PR fixes #5254
The above issue was happening because period (.) was being considered as a separator sequence (PUNCTUATION_OR_SPACE in packages/lexical-react/src/LexicalAutoLinkPlugin.ts) which is wrong.

Additionally, this PR introduces an enhancement to the existing regular expression used for URL validation. The existing regex for URL validation was effective but limited in scope, failing to recognize several common URL formats. With the growing need for more comprehensive URL validation in modern web applications, it became imperative to update our regex to handle a broader range of URLs, including those with user credentials and special domains like 'localhost', as well as IP addresses. To ensure the robustness of the updated regex, a series of tests were conducted with various URL formats. The test results show a comparison between the old variant of the regex and the new enhanced variant. The new variant successfully matches a wider range of URLs, making it a more versatile choice for URL validation.

Test URL Old Variant Match New Variant Match
http://example.com
https://www.example.com
www.example.com
example.com
http://localhost:8000
ftp://example.com
http://example.com/path/to/resource?query=string#fragment
example
http://192.168.1.1
https://example.com:3000/path
http://example.com:8080/path
https://subdomain.example.com
http://127.0.0.1
http://example.com/path/to/page.html
https://example.com?param=value
http://example.co.uk
https://255.255.255.255
https://example.com#anchor
http://example.com/path/to/page.html?query=string#fragment
http://[::1] (IPv6 address)
https://username:[email protected]
ftp://192.168.0.1/resource
http://example (no TLD)
http://.com (no domain name)
https://example.com:invalidport (invalid port)
http:///path/without/domain (missing domain)
http://-example.com (invalid domain start)
http://example-.com (invalid domain end)
http://example..com (double dot in domain)
http://ex..ample.com (double dot in domain)
http://abcdefghij.com (long domain name)

Copy link

vercel bot commented Nov 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 23, 2023 5:43pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 23, 2023 5:43pm

@facebook-github-bot
Copy link
Contributor

Hi @disalechinmay!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 22, 2023
@ivailop7
Copy link
Collaborator

@disalechinmay could you do the CLA, otherwise LGTM

@ivailop7
Copy link
Collaborator

This looks great, could you update the AutoLink tests to reflect your changes and I'll merge it.

@disalechinmay
Copy link
Contributor Author

@ivailop7 - I've updated the tests 🧪
Also updated the regex a bit.

Copy link
Collaborator

@ivailop7 ivailop7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ivailop7 ivailop7 merged commit 0f7c78b into facebook:main Nov 23, 2023
45 checks passed
@disalechinmay disalechinmay deleted the bugfix/autolink-plugin-url-not-being-recognized branch November 24, 2023 14:00
@thorn0
Copy link
Contributor

thorn0 commented Nov 27, 2023

The complexity of this regexp seems problematic. Just open the playground and start typing to see what I mean. My browser starts dying when the input is around 30 characters long and freezes at 40.

@acywatson
Copy link
Contributor

The complexity of this regexp seems problematic. Just open the playground and start typing to see what I mean. My browser starts dying when the input is around 30 characters long and freezes at 40.

It was, in fact, problematic. Reverted it - thanks for the catch.

@moy2010
Copy link
Contributor

moy2010 commented Nov 28, 2023

@acywatson , @thorn0 , the performance issue wasn't caused by this PR. See here for more info.

@acywatson
Copy link
Contributor

@acywatson , @thorn0 , the performance issue wasn't caused by this PR. See here for more info.

I'm pretty certain that it was. If you go back literally one commit and check the preview deployment, the issue isn't there. There may be multiple issues here, but I think this PR is part of the problem at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Problem recognizing input URLs in the autolink plugin.
6 participants