From 298acbc239c437d1806f30f009f65804d9a77697 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 26 Sep 2016 17:56:15 +0200 Subject: [PATCH] Fixed srcset handling --- .../output/node/HtmlOutputNodeImg.class.php | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) 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); } } } -- 2.20.1