@sgiehl opened this Pull Request on January 27th 2021 Member

Description:

On PHP 8 some tests for different encodings in tracking are failing:

1) Piwik\Tests\System\NonUnicodeTest::testApi
Failed to setup fixture: Expected GIF beacon, got: <br/>
'<br />
<b>Fatal error</b>:  Uncaught ValueError: mb_check_encoding(): Argument <a href='/2'>#2</a> ($encoding) must be a valid encoding, &quot;GTF-42&quot; given in /home/travis/build/matomo-org/matomo/core/Tracker/PageUrl.php:241
Stack trace:
<a href='/0'>#0</a> /home/travis/build/matomo-org/matomo/core/Tracker/PageUrl.php(241): mb_check_encoding(\'param\', \'GTF-42\')
<a href='/1'>#1</a> /home/travis/build/matomo-org/matomo/core/Tracker/PageUrl.php(255): Piwik\\Tracker\\PageUrl::reencodeParameterValue(\'param\', \'GTF-42\')
<a href='/2'>#2</a> /home/travis/build/matomo-org/matomo/core/Tracker/PageUrl.php(286): Piwik\\Tracker\\PageUrl::reencodeParametersArray(Array, \'GTF-42\')
<a href='/3'>#3</a> /home/travis/build/matomo-org/matomo/plugins/Actions/Actions/ActionSiteSearch.php(143): Piwik\\Tracker\\PageUrl::reencodeParameters(Array, \'GTF-42\')
<a href='/4'>#4</a> /home/travis/build/matomo-org/matomo/plugins/Actions/Actions/ActionSiteSearch.php(251): Piwik\\Plugins\\Actions\\Actions\\ActionSiteSearch::detectSiteSearchFromUrl(Array, Array, \'GTF-42\')
<a href='/5'>#5</a> /home/travis/build/matomo-org/matomo/plugins/Actions/Actions/ActionSiteSearch.php(45): Piwik\\Plugins\\Actions\\Actions\\ActionSiteSearch-&gt;detectSiteSearch(\'http://example....\')
<a href='/6'>#6</a> /home/travis/build/matomo-org/matomo/core/Tracker/Action.php(163): Piwik\\Plugins\\Actions\\Actions\\ActionSiteSearch::shouldHandle(Object(Piwik\\Tracker\\Request))
<a href='/7'>#7</a> /home/travis/build/matomo-org/matomo/core/Tracker/Action.php(93): Piwik\\Tracker\\Action::getAllActions(Object(Piwik\\Tracker\\Request))
<a href='/8'>#8</a> /home/travis/build/matomo-org/matomo/plugins/Actions/Tracker/ActionsRequestProcessor.php(51): Piwik\\Tracker\\Action::factory(Object(Piwik\\Tracker\\Request))
<a href='/9'>#9</a> /home/travis/build/matomo-org/matomo/core/Tracker/Visit.php(163): Piwik\\Plugins\\Actions\\Tracker\\ActionsRequestProcessor-&gt;processRequestParams(Object(Piwik\\Tracker\\Visit\\VisitProperties), Object(Piwik\\Tracker\\Request))
<a href='/10'>#10</a> /home/travis/build/matomo-org/matomo/core/Tracker.php(160): Piwik\\Tracker\\Visit-&gt;handle()
<a href='/11'>#11</a> /home/travis/build/matomo-org/matomo/core/Tracker/Handler.php(55): Piwik\\Tracker-&gt;trackRequest(Object(Piwik\\Tracker\\Request))
<a href='/12'>#12</a> /home/travis/build/matomo-org/matomo/core/Tracker.php(140): Piwik\\Tracker\\Handler-&gt;process(Object(Piwik\\Tracker), Object(Piwik\\Tracker\\RequestSet))
<a href='/13'>#13</a> /home/travis/build/matomo-org/matomo/core/Tracker.php(115): Piwik\\Tracker-&gt;track(Object(Piwik\\Tracker\\Handler), Object(Piwik\\Tracker\\RequestSet))
<a href='/14'>#14</a> /home/travis/build/matomo-org/matomo/piwik.php(73): Piwik\\Tracker-&gt;main(Object(Piwik\\Tracker\\Handler), Object(Piwik\\Tracker\\RequestSet))
<a href='/15'>#15</a> /home/travis/build/matomo-org/matomo/matomo.php(13): include(\'/home/travis/bu...\')
<a href='/16'>#16</a> /home/travis/build/matomo-org/matomo/tests/PHPUnit/proxy/piwik.php(36): include(\'/home/travis/bu...\')
<a href='/17'>#17</a> /home/travis/build/matomo-org/matomo/tests/PHPUnit/proxy/matomo.php(9): include(\'/home/travis/bu...\')
<a href='/18'>#18</a> {main}
  thrown in <b>/home/travis/build/matomo-org/matomo/core/Tracker/PageUrl.php</b> on line <b>241</b><br />
'
 If you are stuck, you can enable [Tracker] debug=1; in config.ini.php to get more debug info.

This failure is caused by an internal change in mb_detect_encoding. While PHP 7 simply did nothing or failed silently when an invaid encoding was given, PHP 8 now starts throwing a newly introduced ValueError.
For PHP 8 that means a tracking request would fail completely as soon as an invalid encoding is sent with the request. Not sure if that should happen that often, but maybe it might be the case if someone defines an invalid encoding for his website.

I've tested those changes on another branch where tests are running against PHP 8. See https://travis-ci.com/github/matomo-org/matomo/jobs/477061001

Review

  • [ ] Functional review done
  • [ ] Usability review done (is anything maybe unclear or think about anything that would cause people to reach out to support)
  • [ ] Security review done see checklist
  • [ ] Code review done
  • [ ] Tests were added if useful/possible
  • [ ] Reviewed for breaking changes
  • [ ] Developer changelog updated if needed
  • [ ] Documentation added if needed
  • [ ] Existing documentation updated if needed
This Pull Request was closed on January 28th 2021
Powered by GitHub Issue Mirror