Automattic / Automattic/jetpack
Gallery Block: Image Filename wp-image-#.jpg (or .png) Causes Block to Crash
- Dominant language
- PHP
- Stars
- 1.8k
- Forks
- 898
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 774
Description
#### Steps to reproduce the issue
1. Go to WordPress.com dashboard - Site - Media
2. Upload images that have a filename that starts with wp-image-x, where x is any number or combination of numbers. For example, wp-image-123.jpg or wp-image-2352345.png
3. Upload some images that have working filenames. dog.jpg, cat.jpg, etc..
4. Create a new page.
5. Add a Gallery Block to the page, and only include images that have the wp-image-# file format.
6. Add a second Gallery Block to the page, and only include images that have the working file format (cat.jpg, dog.png, etc).
7. Add a third Gallery Block to the page, and include a mixture of both file names. (wp-image-123.jpg, cat.jpg, dog.png, wp-image-245.png)
#### What I expected
I would expect all of the gallery blocks to work.
#### What happened instead
Gallery blocks that have all images with the wp-image-# format will break entirely, and require a page refresh to exit the gallery. This causes this console error:

Gallery blocks that have all images with a standard filename format will work. That part is okay.
Gallery blocks that have a mixture of the two will work, but images using the wp-image-# format will not appear when flipping through the gallery.
**Screenshots**
A testing site displaying all of the above is available, here:
https://satestsitesc.wordpress.com/gallery-block-bug-test-https-github-com-automattic-jetpack-issues-13632/
Also of note:
Images that have the wp-image-# filename don't have most of the data- elements. For example, a working image might look like this:
`
`
While a wp-image-# image will look like this:
`
`
So the split might be failing because `data-orig-size` isn't there. Possibly the root of the console error (screenshot again for posterity):

On the original report, @kwight noted this:
This looks suspect: https://github.com/Automattic/jetpack/blob/master/modules/carousel/jetpack-carousel.php#L396
This is a repost of https://github.com/Automattic/jetpack/issues/13632 - I'm moving it here to file it in the right place (as of now), and close the stale report.
Contributor guide
Research direction
Reproduce the crash with Gallery Blocks containing filenames such as wp-image-123.jpg, then inspect modules/carousel/jetpack-carousel.php around line 396, which the issue identifies as suspect. Compare the available image data for standard and wp-image-# filenames; done means all-image and mixed galleries render and navigate without crashing or omitting images.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100