-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Navigation Block: Properly decode URL-encoded links #46435
Changes from all commits
f1f750c
8256ad3
4283088
4ae395e
8150dad
4704426
3a29c0e
3505a5f
9430754
4cfabbb
2cb90f0
ddd1f9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,7 +89,7 @@ export const updateAttributes = ( | |
|
||
setAttributes( { | ||
// Passed `url` may already be encoded. To prevent double encoding, decodeURI is executed to revert to the original string. | ||
...( newUrl && { url: encodeURI( safeDecodeURI( newUrl ) ) } ), | ||
...{ url: newUrl ? encodeURI( safeDecodeURI( newUrl ) ) : newUrl }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still not super clear why it was necessary to
Maybe because the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @danielbachhuber you were right. The reason that this was stripped out is because of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@kozer For posterity, can you provide a full step-by-step documentation of what's going on? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For sure @danielbachhuber! So, the process is the following:
This is the reason why I also put those steps in the description of this pr. Given that, I assume this is ok to be merged. |
||
...( label && { label } ), | ||
...( undefined !== opensInNewTab && { opensInNewTab } ), | ||
...( id && Number.isInteger( id ) && { id } ), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we consolidate these two functions into one function called
block_core_navigation_link_maybe_urldecode()
?For better or for worse,
maybe_*
functions are a common pattern in WordPress core: https://developer.wordpress.org/?s=maybeIt seems like there are some PHPCS issues that need to be fixed too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer having them as two separate functions, as it's clear what each one of them is doing, and we can reuse
is_url_encoded
for testing encoded URLs elsewhere if we need to instead of tying those two functions together and producing a "side effect" if the URL is encoded.However, I'll rename the
urldecode_once
tomaybe_urldecode
to match the common pattern in WordPress core.Thanks for pointing this out!
Can you elaborate a bit more on this? I don't see any PHPCS issues locally for those two functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kozer Given this will eventually be included in WordPress core, I'd like them consolidated to one function to match the pattern already established in WordPress core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danielbachhuber Doesn't the
maybe_urldecode
renaming establish that pattern?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kozer If it's only one
block_core_navigation_link_maybe_urldecode()
function, then yes 😊In the context of a large open source project, we shouldn't introduce two functions if we only need one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danielbachhuber I made the change as requested!
A side note:
I'm not sure if the phpcs errors you mentioned are related to tabs vs spaces. Neither vscode or neovim show any warnings/errors to me.
Are tabs the way to go in PHP-related files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kozer Here's the failing test: https://github.com/WordPress/gutenberg/actions/runs/3830602130/jobs/6518686126
The failing test runs
npm run lint:php
:You can run
npm run lint:php
in your local environment to see all of the same errors.I use this VS Code extension to integrate PHPCS:
Name: PHP Sniffer & Beautifier
Id: valeryanm.vscode-phpsab
Description: PHP Sniffer & Beautifier for Visual Studio Code
Version: 0.0.15
Publisher: Samuel Hilson
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ValeryanM.vscode-phpsab
You can see all of WordPress' PHP coding standards here: https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/