Skip to content
Snippets Groups Projects

fix(3354345): check if the SRCSET attr is available and adding logic to handle it correctly.

1 file
+ 30
0
Compare changes
  • Side-by-side
  • Inline
+ 30
0
@@ -118,6 +118,36 @@ function _pathologic_filter($text, $settings, $hash) {
* Process and replace paths. preg_replace_callback() callback.
*/
function _pathologic_replace($matches) {
$pattern_split = '/\s\d+w/';
$pattern_match = '/\s(\d+w)/';
if (
$matches[1] === 'srcset' &&
preg_match($pattern_split, $matches[2])
) {
$output = '';
$multiple_parts = preg_split($pattern_split, $matches[2]);
preg_match_all($pattern_match, $matches[2], $multiple_matches);
foreach ($multiple_matches[1] as $index => $key) {
$fixed_path = _pathologic_replace_individual(['', '', trim(str_replace(', ', '', $multiple_parts[$index]))]);
$fixed_path = trim(str_replace('="', '', $fixed_path));
$output .= $fixed_path . ' ' . $key . ', ';
}
$output = $matches[1] . '="' . substr($output, 0, -2) . '"';
return $output;
}
else {
return _pathologic_replace_individual($matches);
}
}
/**
* This function returns replaced pathologic for individual URLs.
*/
function _pathologic_replace_individual($matches) {
// Get the base path.
global $base_path;
Loading