elementor / elementor/static-html-output

Images with data srcsets result in undefined offset error while generating

Open
#128 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
PHP
Stars
128
Forks
35
PR merge metrics
No merged PRs in 30d

Description

One of my pages has the following image:
```html
my image caption
```

When running `wp wp2static generate` I get spammed with millions of lines of
```
PHP Notice: Undefined offset: 1 in /path/to/wp-content/plugins/static-html-output-plugin/plugin/WP2Static/HTMLProcessor.php on line 136
PHP Stack trace:
PHP 1. {main}() /usr/local/Cellar/wp-cli/2.4.0/bin/wp:0
PHP 2. include() /usr/local/Cellar/wp-cli/2.4.0/bin/wp:4
PHP 3. include() phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/php/boot-phar.php:11
PHP 4. WP_CLI\bootstrap() phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php:27
PHP 5. WP_CLI\Bootstrap\LaunchRunner->process() phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php:74
PHP 6. WP_CLI\Runner->start() phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php:23
PHP 7. WP_CLI\Runner->run_command_and_exit() phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:1160
PHP 8. WP_CLI\Runner->run_command() phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:394
PHP 9. WP_CLI\Dispatcher\Subcommand->invoke() phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:371
PHP 10. call_user_func:{phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php:451}() phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php:451
PHP 11. WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure:phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php:95-102}() phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php:451
PHP 12. call_user_func:{phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php:98}() phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php:98
PHP 13. WP2Static_CLI->generate() phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php:98
PHP 14. SiteCrawler->crawl_site() /path/to/wp-content/plugins/static-html-output-plugin/plugin/wp2static-wp-cli-commands.php:2
PHP 15. SiteCrawler->crawlABitMore() /path/to/wp-content/plugins/static-html-output-plugin/plugin/WP2Static/SiteCrawler.php:2
PHP 16. SiteCrawler->loadFileForProcessing() /path/to/wp-content/plugins/static-html-output-plugin/plugin/WP2Static/SiteCrawler.php:2
PHP 17. HTMLProcessor->processHTML() /path/to/wp-content/plugins/static-html-output-plugin/plugin/WP2Static/SiteCrawler.php:2
PHP 18. HTMLProcessor->processImageSrcSet() /path/to/wp-content/plugins/static-html-output-plugin/plugin/WP2Static/HTMLProcessor.php:28
```

The error is coming from *HTMLProcessor.php*'s `processImageSrcSet` method:
```php
$src_set = $element->getAttribute('srcset');
$src_set_lines = explode(',', $src_set);
foreach ($src_set_lines as $src_set_line) {
$all_pieces = explode(' ', $src_set_line);
$pieces = array_filter($all_pieces);
$pieces = array_values($pieces);
$url = $pieces[0];
$dimension = $pieces[1];
```
The problem is the `explode` by comma line. My srcset includes a comma so it's incorrectly exploded.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.