Image Block: Handle image URLs without protocol#75135
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +89 B (0%) Total Size: 3 MB
ℹ️ View Unchanged
|
| // Handle URLs without protocol. | ||
| const normalizedNewURL = getProtocol( newURL ) | ||
| ? newURL | ||
| : prependHTTPS( newURL ); |
There was a problem hiding this comment.
I think the prepend methods already check and bail out early, if URL has protocol.
There was a problem hiding this comment.
I thought so too, but I couldn't find that:
prependHTTPS()bails only if the URL starts withhttp://and falls back toprependHTTPprependHTTP()will allow any usable "URL", allowing relative paths like#aboutor?page=1
So I thought it's best to bet on the safe side.
There was a problem hiding this comment.
Good point. I wonder if similar early fallback is worth adding to this methods.
There was a problem hiding this comment.
Maybe. Worth checking all the usage before making a call, though.
|
Thanks for the quick look, @Mamaduka 🙌 |
Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
What?
Handle image URLs without protocol when inserting from URL in the Image block.
The last part of #74738.
Why?
Currently, if the user inputs a URL without a protocol, it won't load.
See #74738.
Originally #74738 reported the bug for both blocks, and #74964 only fixed it for the Video block, so this one fixes it for the Image block.
How?
We're prepending HTTPS to the URL when necessary.
Also adding a simple e2e test for this behavior.
Testing Instructions
Test instructions:
Testing Instructions for Keyboard
Same
Screenshots or screencast
Nothing was visibly changed.