Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix preg_match in enforceHttpEncoding #4623

Merged
merged 1 commit into from
Sep 19, 2022

Conversation

marienfressinaud
Copy link
Member

Changes proposed in this pull request:

  • test correctly the success of preg_match in enforceHttpEncoding

How to test the feature manually:

  1. setup a XPath feed with a website not declaring a charset in its content type
  2. refresh the feed
  3. verify there is no errors

Pull request checklist:

  • clear commit messages
  • code manually tested
  • unit tests written (optional if too hard) N/A
  • documentation updated

Additional information can be found in the documentation.

`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.
@Alkarex Alkarex added this to the 1.21.0 milestone Sep 19, 2022
@Alkarex Alkarex merged commit 6813e16 into FreshRSS:edge Sep 19, 2022
@@ -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];
Copy link
Member

@Alkarex Alkarex Sep 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, should have been == false or simply just the boolean expression

@Alkarex Alkarex modified the milestones: 1.21.0, 1.20.1 Sep 19, 2022
@marienfressinaud marienfressinaud deleted the fix/enforceHttpEncoding branch September 19, 2022 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants