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

Editor automatically creates links for phrases that look like URLs #26266

Closed
msaari opened this issue Oct 19, 2020 · 3 comments
Closed

Editor automatically creates links for phrases that look like URLs #26266

msaari opened this issue Oct 19, 2020 · 3 comments
Labels
[Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) [Type] Enhancement A suggestion for improvement.

Comments

@msaari
Copy link

msaari commented Oct 19, 2020

Describe the bug
When you paint some text and add a link to it, if the text vaguely looks like an URL, the editor will use the text as an URL.

To reproduce
Steps to reproduce the behavior:

  1. Create a new post.
  2. Type "magic: the gathering" or something else starts with a word followed by a colon.
  3. Paint the text.
  4. Click the link button to create a link.

Expected behavior
I would expect the editor not to assume the non-URL text to be an URL, and instead ask for the link target like it usually does. Perhaps the editor should check better for the URL pattern and only assume URLs where the protocol matches an actual protocol (perhaps use the list of permanent protocols as defined in the standards).

Editor version (please complete the following information):

  • WordPress version: 5.5.1
  • Gutenberg version: 9.1.1 (this happens also with the default editor)

Desktop (please complete the following information):
The problem is independent of browser or OS.

Additional context
I'm interested in providing code to fix this, but could use some pointers on where this behaviour happens – it's a big codebase and this isn't terribly easy to search for.

@msaari
Copy link
Author

msaari commented Oct 20, 2020

A bit of digging, and looks like the main problem here is that isValidProtocol() which checks if the protocol part of the URL is valid, doesn't really check if it's a real protocol or not. It just checks if the format is valid or not.

Now this makes some sense and it doesn't make sense to change isValidProtocol(). I would suggest creating a function isCommonProtocol() that would check for the most common protocols used (http, https, mailto, tel, ftp, etc.). In the link creation, this could be then checked and only URLs with these common protocols would be considered a link.

@talldan talldan added [Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) [Type] Enhancement A suggestion for improvement. labels Oct 22, 2020
@talldan
Copy link
Contributor

talldan commented Oct 22, 2020

I'm interested in providing code to fix this, but could use some pointers on where this behaviour happens – it's a big codebase and this isn't terribly easy to search for.

Thanks @msaari, looks like you found the place in your follow up comment. It'd be great to see a PR exploring this if you're still interested. Drop a comment if you need any help contributing, here's a link to the docs:
https://github.com/WordPress/gutenberg/blob/master/docs/contributors/develop.md

@getdave
Copy link
Contributor

getdave commented Mar 15, 2023

Closing in favour of #38497

@getdave getdave closed this as completed Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

3 participants