Image parser uses a data: placeholder from data-src as the image URL, so the real src misses srcset enhancement
维护者通常 1 天内回复
@selul 已经在做这个了。
开始于 2026年10月20日。
评估
调研方向
Start with Optml_Manager::parse_images_from_html() in inc/manager.php and trace how its selected URL reaches Optml_Tag_Replacer::process_image_tags() and add_missing_srcset_attributes(). Reproduce the two attribute orders from the issue in PHPUnit, using profiler data keyed to the real src and reported data-opt-id; check the replacer and lazy-load suites plus integrations using possible_src_attributes(). Done when the real image URL drives per-tag processing and the data: placeholder order receives the expected srcset and sizes.
由索引模型根据 Issue 内容生成。
描述
Summary
When an image has a lazy-load attribute that holds a data: placeholder before its real src, the image parser takes the placeholder as the image's URL. The tag replacer then works on that placeholder instead of the real image, so the image never gets the page profiler's missing-srcset / sizes entries.
<img data-src="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" src="https://example.com/wp-content/uploads/2026/10/photo.jpg" alt="Test" />
The same image with src first, or without the data-src, is enhanced normally.
Found by the QA agent while testing #1184 / #1185. It also happens on development, so it isn't caused by #1185.
What happens
Optml_Manager::parse_images_from_html()(inc/manager.php) matches the firstsrcorpossible_src_attributes()attribute it finds and returns its value asimg_url. Here that'sdata-src, soimg_urlisdata:image/gif.Optml_Tag_Replacer::process_image_tags()goes ahead with that URL:can_replace_tag( 'data:image/gif' )returnstrue.- The "optimized" URL for
data:image/gifis the placeholder itself, soadd_missing_srcset_attributes()builds every candidate from it.esc_url()turns each one into an empty string, and nothing is added. - The real
srcis still moved to the CDN by the later URL replacement pass. Only the tag-level work is done against the wrong URL.
The image also gets data-opt-id computed from the placeholder URL (get_id_by_url( 'data:image/gif' )) instead of the real image. So every image with that placeholder shares one profiler ID.
Reproduction
PHPUnit, with profiler data seeded for the image (keyed by the real src ID and by the data-opt-id the browser profiler reports, assets/js/modules/srcset-detector.js:139):
| Tag shape | development |
#1185 |
|---|---|---|
data-src="data:…" before src |
not enhanced | not enhanced |
src before data-src="data:…" |
enhanced | enhanced |
no data-src |
enhanced | enhanced |
Impact
- Images whose markup puts a lazy-load
data:placeholder attribute beforesrcmiss the profiler's responsivesrcset/sizes. - Other per-tag work that uses
img_url(crop and dimension handling, profiler IDs, possibly lazy-load decisions) runs against the placeholder. This needs checking.
Possible fix
When picking an image's URL, skip attributes whose value is a data: URI, so a real src is used. This changes what parse_images_from_html() returns, which feeds every image replacement. It needs its own tests across the replacer and lazy-load suites, and a check against possible_src_attributes() integrations.
- 主要语言
- PHP
- 星标
- 74
- 派生
- 14
- 平均合并
- 2 天 9 小时
- 30 天内合并 PR
- 22
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Codeinwp/optimole-wp 的其他 Issue
-
Image URL replacement passes an integer cache token to the Optimole SDK可能已有人在做 @selul 于 1 天前认领。 未关闭bug bug-report bug-report-triage crash-report
难度 3/5 1-2 天 新手友好度 55/100
Codeinwp/optimole-wp#1187 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
customer report feature-request-triage
难度 5/5 一周以上 新手友好度 35/100
Codeinwp/optimole-wp#1179 ·
维护者通常 1 天内回复
-
customer report feature-request-triage
难度 4/5 3-5 天 新手友好度 54/100
Codeinwp/optimole-wp#1178 ·
维护者通常 1 天内回复
-
bug bug-report bug-report-triage crash-report
难度 4/5 3-5 天 新手友好度 45/100
Codeinwp/optimole-wp#1163 · 4 条评论 ·
维护者通常 1 天内回复
-
customer report feature-request-triage
难度 3/5 1-2 天 新手友好度 55/100
Codeinwp/optimole-wp#1151 ·
维护者通常 1 天内回复
查看 Codeinwp/optimole-wp 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 64/100
kanboard/kanboard#5929 · 1 条评论 · 3 个 reaction ·
维护者通常 5 天内回复
-
Rebuild 6.2.3 images on PHP 8.5.12 / 8.4.27 / 8.3.36 / 8.2.35 (CVE-2026-109618, CVE-2026-109619)未关闭
难度 2/5 1-3 小时 新手友好度 66/100
swoole/docker-swoole#65 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 79/100
PHP-CS-Fixer/PHP-CS-Fixer#9899 ·
维护者通常 1 天内回复
-
REST: Add missing text domain and fix typos in REST API controller strings可能已有人在做 @devmuhib009 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
-
难度 2/5 1-3 小时 新手友好度 68/100