WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.16k stars 4.05k forks source link

Relative scheme images no longer display in the editor #54262

Open peterwilsoncc opened 10 months ago

peterwilsoncc commented 10 months ago

Description

In WordPress 6.3 and the current version of the Gutenberg plugin, 16.6.0, images with relative schemes are not displayed correctly in the block editor. On the front end they render as expected.

In the editor, the images are shown as a broken image and -- browser dependent -- the alt text shown in it's place.

Step-by-step reproduction instructions

  1. Install WordPress 6.3 locally
  2. In the wp-config file, define a relative content URL constant: define( 'WP_CONTENT_URL', '//example.local/wp-content' );
  3. Create a post in the block editor
  4. Insert an image block
  5. Upload an image to the image block/library
  6. The image fails to load
  7. Preview the post in a new tab: the image does display
  8. Switch to the code editor
  9. Modify the image URL to include the scheme
  10. Exit the code editor
  11. The image now displays

Screenshots, screen recording, code snippet

WordPress 6.3 (with and without the latest version of Gutenberg active)

Screen Shot 2023-09-08 at 10 48 42 am

WordPress 6.2 (without Gutenberg active)

Screen Shot 2023-09-08 at 10 50 34 am

Environment info

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

tambourine-man commented 10 months ago

Same here, basically makes using relative path in WP_CONTENT_URL impossible.

Pat-Relentless commented 7 months ago

Also have this issue if you define a gutenberg template for a post type that uses an image:

"template": [
[
    "core/cover",
    {
        "url": "/wp-content/uploads/2023/11/image.jpg",
        "id": 38,
        "dimRatio": 30,
        "overlayColor": "forest-green",
        "layout": {
            "type": "constrained"
        }
    },

I suspect this has something to do with the editor being rendered in an iframe where the src starts with "blob". Likely a security issue, but would love to be able to use relative image urls in a block template...