Skip to content

Commit

Permalink
fix: Fix preg_match in enforceHttpEncoding (#4623)
Browse files Browse the repository at this point in the history
`preg_match` can return `1`, `0` or `false`. In this last case,
`enforceHttpEncoding` was trying to access `$matches[1]`, even if the regex wasn't matching.
  • Loading branch information
marienfressinaud authored Sep 19, 2022
1 parent 6bed64f commit 6813e16
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/lib_rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function cleanCache(int $hours = 720) {
* @return string an HTML string with XML encoding information for DOMDocument::loadHTML()
*/
function enforceHttpEncoding(string $html, string $contentType = ''): string {
$httpCharset = preg_match('/\bcharset=([0-9a-z_-]{2,12})$/i', $contentType, $matches) === false ? '' : $matches[1];
$httpCharset = preg_match('/\bcharset=([0-9a-z_-]{2,12})$/i', $contentType, $matches) === 1 ? $matches[1] : '';
if ($httpCharset == '') {
// No charset defined by HTTP, do nothing
return $html;
Expand Down

0 comments on commit 6813e16

Please sign in to comment.