Skip to content

Fix Navigation Link url escaping#19679

Merged
noahtallen merged 3 commits intoWordPress:masterfrom
Addison-Stavlo:fix/nav-link-href-escaping
Jan 15, 2020
Merged

Fix Navigation Link url escaping#19679
noahtallen merged 3 commits intoWordPress:masterfrom
Addison-Stavlo:fix/nav-link-href-escaping

Conversation

@Addison-Stavlo
Copy link
Contributor

@Addison-Stavlo Addison-Stavlo commented Jan 15, 2020

Description

Fix for issue #19632 .

This PR updates the navigation-link component to pass the url through the escape function on saving a new link. Previously, a link such as http://example.com/?s=<> would lead to http://example.com/?s= when used on the front-end. Now, links saved with the url passed through the escape function will lead to the expected href on the front end.

How has this been tested?

Tested on local docker environment using links saved on the Navigation block.

Screenshots

In the editor

Saved without escape function
Screen Shot 2020-01-14 at 5 18 50 PM

Saved with escape function
Screen Shot 2020-01-14 at 5 18 59 PM

On the Front-End

Saved without escape function
Screen Shot 2020-01-14 at 5 21 48 PM

Saved with escape function
Screen Shot 2020-01-14 at 5 22 02 PM

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.
  • [n/a] My code has proper inline documentation.
  • [n/a] I've included developer documentation if appropriate.

@WunderBart
Copy link
Member

Can we use native encodeURI instead of lodash's escape()?

A good related issue about it: https://stackoverflow.com/questions/75980/when-are-you-supposed-to-use-escape-instead-of-encodeuri-encodeuricomponent

@Addison-Stavlo
Copy link
Contributor Author

Addison-Stavlo commented Jan 15, 2020

Can we use native encodeURI instead of lodash's escape()?

Definitely! Thanks for linking that issue that is great to know. I have updated it to now use encodeURI instead of escape. Now, on the editor, the link looks a bit better too but still leads to the correct place on the front end.

With encodeURI function
Screen Shot 2020-01-15 at 1 15 35 PM

Copy link
Member

@WunderBart WunderBart left a comment

Choose a reason for hiding this comment

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

Looks good! :shipit:

@noahtallen
Copy link
Member

I'll go ahead and merge this for you since everything is looking good!

@noahtallen noahtallen merged commit ec6ea4c into WordPress:master Jan 15, 2020
@Addison-Stavlo Addison-Stavlo deleted the fix/nav-link-href-escaping branch January 15, 2020 23:51
@WunderBart WunderBart added [Block] Navigation Affects the Navigation Block Good First Issue An issue that's suitable for someone looking to contribute for the first time labels Jan 16, 2020
@ellatrix ellatrix added this to the Gutenberg 7.3 milestone Jan 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Navigation Affects the Navigation Block Good First Issue An issue that's suitable for someone looking to contribute for the first time

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants