Skip to content

Conversation

shrivastavanolo
Copy link
Contributor

@shrivastavanolo shrivastavanolo commented Aug 1, 2025

What?

Closes #35910

Prepending http:// to a link without protocol ( for eg. 'www.example.com' ) added to the image block for correct linking.

Why?

When a valid link without protocol ( for eg. 'www.example.com' ) is added to an image in Gutenberg, the WordPress site's base URL is incorrectly appended to the link, resulting in a 404 error. This behavior is inconsistent with links added in paragraph blocks, which link correctly.

Similar to #47311 which uses this methodology for the button block

How?

Modifies image-url-input-ui.js using prependHttp() from @wordpress/url.

Additionally, a new test case has been added to image.spec.js.

Testing Instructions

  • Create a Page
  • Add an Image Block
  • Add a link without http:// or https:// using the block toolbar
  • Publish the Page
  • Click the Image on the published Page

@shrivastavanolo shrivastavanolo changed the title Image Block: Prepend HTTP to Buttons block links when missing protocol Image Block: Prepend HTTP to links when missing protocol Aug 1, 2025
@shrivastavanolo shrivastavanolo marked this pull request as ready for review August 1, 2025 16:17
Copy link

github-actions bot commented Aug 1, 2025

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 props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @porg.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: porg.

Co-authored-by: shrivastavanolo <shreya0shrivastava@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: glendaviesnz <glendaviesnz@git.wordpress.org>
Co-authored-by: skorasaurus <skorasaurus@git.wordpress.org>
Co-authored-by: Robertght <robertghetau@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Block] Image Affects the Image Block labels Aug 2, 2025
@Mamaduka Mamaduka self-requested a review August 2, 2025 05:48
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Thanks, @shrivastavanolo!

Left a couple of notes regarding e2e tests, but the general update looks good.

imageBlock.locator( 'data-testid=form-file-upload-input' )
);

await page.getByLabel( 'Block tools' ).getByLabel( 'Link' ).click();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
await page.getByLabel( 'Block tools' ).getByLabel( 'Link' ).click();
await editor.clickBlockToolbarButton( 'Link' );

There's a helper for this.

Comment on lines 717 to 719
// This form lacks distinguishing qualities other than the
// class name, so we use page.locator() instead of page.getByRole()
const form = page.locator( '.block-editor-url-popover__link-editor' );
Copy link
Member

Choose a reason for hiding this comment

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

Let's target URL compobox instead, since we can reuse it.

page.getByRole( 'combobox', { name: 'URL' } );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @Mamaduka Thanks for the review!

Here, I scoped both the URL input and the Apply button within the popover container (.block-editor-url-popover__link-editor) since the Apply button was clashing elsewhere on the page. Keeping it scoped also made sense for the URL input to keep things consistent and avoid any selector issues.

Comment on lines 721 to 724
const url = 'example.com';

await expect( form.getByLabel( 'URL' ) ).toBeFocused();
await form.getByLabel( 'URL' ).fill( url );
Copy link
Member

Choose a reason for hiding this comment

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

  • The url variable is only used once. We can just inline the initial URL.
  • The locator.fill ensures that the field receives focus before filling it. There's no need for the toBeFocused assertion. See details section: https://playwright.dev/docs/api/class-locator#locator-fill.
  • Avoid using getByLabel when possible.

Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Thanks for the follow-up, @shrivastavanolo!

@Mamaduka Mamaduka merged commit d206bc6 into WordPress:trunk Aug 4, 2025
63 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.4 milestone Aug 4, 2025
@porg
Copy link

porg commented Aug 6, 2025

I argued that under contemporary web practices and SEO that:

Yet according to your summary your PR seems to:

Prepending http:// to a link without protocol

HTTPS should be the default. Could we agree on that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Image Affects the Image Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Image blocks with www links append the site's base URL to the link.
3 participants