Skip to content

Commit

Permalink
Rewrite logic and add exception for false positive when checking libx…
Browse files Browse the repository at this point in the history
…ml version
  • Loading branch information
schlessera committed May 12, 2020
1 parent 0cda75a commit ba20769
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
4 changes: 4 additions & 0 deletions lib/common/phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ parameters:
- %currentWorkingDirectory%/vendor/autoload.php
ignoreErrors:
- '#^PHPDoc tag @throws with type AmpProject\\Exception\\FailedRemoteRequest is not subtype of Throwable$#'
-
message: '#^If condition is always false\.$#'
path: 'src/Dom/Document.php'
# See https://github.com/phpstan/phpstan/issues/3291
36 changes: 18 additions & 18 deletions lib/common/src/Dom/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -847,26 +847,26 @@ private function restoreSelfClosingTags($html)
*/
private function maybeReplaceNoscriptElements($html)
{
if (! version_compare(LIBXML_DOTTED_VERSION, '2.8', '<')) {
return $html;
if (version_compare(LIBXML_DOTTED_VERSION, '2.8', '<')) {
$html = preg_replace_callback(
'#^.+?(?=<body)#is',
function ($headMatches) {
return preg_replace_callback(
'#<noscript[^>]*>.*?</noscript>#si',
function ($noscriptMatches) {
$placeholder = sprintf('<!--noscript:%s-->', (string)$this->rand());

$this->noscriptPlaceholderComments[$placeholder] = $noscriptMatches[0];
return $placeholder;
},
$headMatches[0]
);
},
$html
);
}

return preg_replace_callback(
'#^.+?(?=<body)#is',
function ($headMatches) {
return preg_replace_callback(
'#<noscript[^>]*>.*?</noscript>#si',
function ($noscriptMatches) {
$placeholder = sprintf('<!--noscript:%s-->', (string)$this->rand());

$this->noscriptPlaceholderComments[$placeholder] = $noscriptMatches[0];
return $placeholder;
},
$headMatches[0]
);
},
$html
);
return $html;
}

/**
Expand Down

0 comments on commit ba20769

Please sign in to comment.