Strip script and style tags through ::clean() method instead of preg_replace

Huge tags can lead to a failure of preg_replace, thus erasing the whole
fetched content.

Fixes https://github.com/wallabag/wallabag/issues/5847

Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
pull/77/head 2.0.1
Kevin Decherf 4 years ago committed by Jeremy Benoist
parent 0c0653dad6
commit 6689f19956
No known key found for this signature in database
GPG Key ID: BCA73962457ACC3C
  1. 7
      src/Readability.php

@ -108,10 +108,6 @@ class Readability implements LoggerAwareInterface
protected $useTidy;
// raw HTML filters
protected $pre_filters = [
// remove obvious scripts
'!<script[^>]*>(.*?)</script>!is' => '',
// remove obvious styles
'!<style[^>]*>(.*?)</style>!is' => '',
// remove spans as we redefine styles and they're probably special-styled
'!</?span[^>]*>!is' => '',
// HACK: firewall-filtered content
@ -366,6 +362,9 @@ class Readability implements LoggerAwareInterface
$this->logger->debug($this->lightClean ? 'Light clean enabled.' : 'Standard clean enabled.');
$this->clean($articleContent, 'style');
$this->clean($articleContent, 'script');
$this->cleanStyles($articleContent);
$this->killBreaks($articleContent);

Loading…
Cancel
Save