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

Ensure only valid URLs or anchors within text are automatically created as links #32663

Merged
merged 4 commits into from
Jun 28, 2021

Conversation

tjcafferkey
Copy link
Contributor

@tjcafferkey tjcafferkey commented Jun 14, 2021

Fixes #32301

Description

  • Used isValidHref within addLink function to check the validity of selected text

How has this been tested?

  • Create or edit an existing post.
  • Add text that has a ": " within it such as this: is invalid text
  • Highlight and select the text, then click the Link icon to link the selected text
  • Check that the highlighted text isn't auto-populated in the input field as the destination URL.

Unit tests also included.

Before After
Screenshot 2021-06-14 at 12 52 05 Screenshot 2021-06-14 at 12 51 37

Types of changes

Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @tjcafferkey! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jun 14, 2021
@getdave
Copy link
Contributor

getdave commented Jun 15, 2021

I think isValidHref should be moved to @wordpress/url. @talldan any thoughts on that? isUrl is fairly lenient on what you might consider a valid URL.

Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

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

Hi Tom 👋

Thanks for contributing to Gutenberg 😄

This looks good to me and seems like a positive change.

I wonder whether you'd consider adding an e2e test to cover this scenario?

https://github.com/WordPress/gutenberg/blob/trunk/packages/e2e-tests/specs/editor/various/links.test.js

All the building blocks should be there in the other tests.

npm run test-e2e packages/e2e-tests/specs/editor/various/links.test.js should run the tests. There are docs on testing as well with a section on e2e tests.

@tjcafferkey
Copy link
Contributor Author

tjcafferkey commented Jun 16, 2021

I wonder whether you'd consider adding an e2e test to cover this scenario?

Yeah shouldn't be a problem :) I'll update the PR soon with some E2E coverage. Thanks for pointing me in the right direction.

Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

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

Thanks so much for the e2e test. Some small ideas and then we're good to go.

packages/e2e-tests/specs/editor/various/links.test.js Outdated Show resolved Hide resolved
packages/e2e-tests/specs/editor/various/links.test.js Outdated Show resolved Hide resolved
packages/e2e-tests/specs/editor/various/links.test.js Outdated Show resolved Hide resolved
@talldan
Copy link
Contributor

talldan commented Jun 17, 2021

I think isValidHref should be moved to @wordpress/url. @talldan any thoughts on that? isUrl is fairly lenient on what you might consider a valid URL.

It wasn't moved there originally because the function validates anchor links, which aren't URLs. Maybe that isn't a strong enough reason not to move it there, but I think it shouldn't be confused with a URL checker.

Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

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

Looking good @tjcafferkey 🥇

Thanks for contributing 🤝

@talldan talldan merged commit 96a8781 into WordPress:trunk Jun 28, 2021
@github-actions
Copy link

Congratulations on your first merged pull request, @tjcafferkey! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts:

https://profiles.wordpress.org/me/profile/edit/

And if you don't have a WordPress.org account, you can create one on this page:

https://login.wordpress.org/register

Kudos!

@talldan
Copy link
Contributor

talldan commented Jun 28, 2021

This also fixed #33009 🎉

Thanks for the contribution @tjcafferkey.

@talldan talldan added [Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) [Type] Bug An existing feature does not function as intended labels Jun 28, 2021
@talldan talldan changed the title Use isValidHref in addLink function to check validity of selected text Ensure only valid URLs or anchors within text are automatically created as links Jun 28, 2021
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) First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Linking selected text containing a colon is interpreted as a URL
3 participants