From: Alexander Ebert Date: Mon, 26 Sep 2016 15:56:15 +0000 (+0200) Subject: Fixed srcset handling X-Git-Tag: 3.0.0_Beta_2~115 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=298acbc239c437d1806f30f009f65804d9a77697;p=GitHub%2FWoltLab%2FWCF.git Fixed srcset handling --- diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeImg.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeImg.class.php index 15a5e3bfe3..70cb8741ab 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeImg.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeImg.class.php @@ -4,8 +4,10 @@ use wcf\data\smiley\Smiley; use wcf\data\smiley\SmileyCache; use wcf\system\html\node\AbstractHtmlNodeProcessor; use wcf\system\request\LinkHandler; +use wcf\util\DOMUtil; use wcf\util\exception\CryptoException; use wcf\util\CryptoUtil; +use wcf\util\StringUtil; /** * Processes images. @@ -52,8 +54,30 @@ class HtmlOutputNodeImg extends AbstractHtmlOutputNode { } else if (MODULE_IMAGE_PROXY) { $src = $element->getAttribute('src'); - if ($src) { - $element->setAttribute('src', $this->getProxyLink($src)); + if (!$src) { + DOMUtil::removeNode($element); + continue; + } + + $element->setAttribute('src', $this->getProxyLink($src)); + + $srcset = $element->getAttribute('srcset'); + if ($srcset) { + // simplified regex to check if it appears to be a valid list of sources + if (!preg_match('~^[^\s]+\s+[0-9\.]+[wx](,\s*[^\s]+\s+[0-9\.]+[wx])*~', $srcset)) { + $element->removeAttribute('srcset'); + continue; + } + + $sources = explode(',', $srcset); + $srcset = ''; + foreach ($sources as $source) { + $tmp = preg_split('~\s+~', StringUtil::trim($source)); + if (!empty($srcset)) $srcset .= ', '; + $srcset .= $this->getProxyLink($tmp[0]) . ' ' . $tmp[1]; + } + + $element->setAttribute('srcset', $srcset); } } }