diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2021-01-21 04:50:03 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-21 04:50:03 +0300 |
commit | 23d551750442d12975ee9c2af6f73ac9bbf75c1a (patch) | |
tree | 822c5fec6e12b832fcc3fefb3a9beb4af6084919 | |
parent | f538b0b5ece37aaf07b71b3869b6a752b0388e68 (diff) |
Custom tracking timestamp should return an integer to prevent HTTP 500 tracking error (#17127)
* Custom tracking timestamp should return an integer to prevent HTTP 500 tracking error
Eg
```
curl -i -X POST -d '{"requests":["?idsite=1&rec=1&idgoal=21&apiv=1&_id=50d60fcd18ff0c7e&cdt=1610168419&revenue=0&send_image=0","?idsite=1&rec=1&idgoal=21&apiv=1&_id=50d60fcd18ff0c7e&cdt=1610168419&revenue=0&send_image=0"]}' http://your.site/matomo.php
```
Can trigger an HTTP 500 error when the request is authenticated (or when using a recent timestamp). That's because when for example A/B tests are configured, then it does a `Date::factory($request->getCurrentTimestamp))` where the timestamp is a `string` and thus the Date class would trigger an exception.
Making sure we return an integer will fix all possible uses.
* fix tests
Co-authored-by: diosmosis <diosmosis@users.noreply.github.com>
-rw-r--r-- | core/Tracker/Request.php | 2 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/Tracker/RequestTest.php | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/core/Tracker/Request.php b/core/Tracker/Request.php index 786624439d..0a85a95aeb 100644 --- a/core/Tracker/Request.php +++ b/core/Tracker/Request.php @@ -543,7 +543,7 @@ class Request } } - return $cdt; + return (int) $cdt; } /** diff --git a/tests/PHPUnit/Integration/Tracker/RequestTest.php b/tests/PHPUnit/Integration/Tracker/RequestTest.php index 9056a37d41..80835701cf 100644 --- a/tests/PHPUnit/Integration/Tracker/RequestTest.php +++ b/tests/PHPUnit/Integration/Tracker/RequestTest.php @@ -257,7 +257,7 @@ class RequestTest extends IntegrationTestCase $request = $this->buildRequest(array('cdt' => '' . ($this->time - 5))); $request->setCurrentTimestamp($this->time); - $this->assertSame('' . ($this->time - 5), $request->getCurrentTimestamp()); + $this->assertSame(($this->time - 5), $request->getCurrentTimestamp()); } public function test_cdt_ShouldReturnTheCustomTimestamp_IfAuthenticatedAndValid() @@ -265,7 +265,7 @@ class RequestTest extends IntegrationTestCase $request = $this->buildRequest(array('cdt' => '' . ($this->time - 86500))); $request->setCurrentTimestamp($this->time); $request->setIsAuthenticated(); - $this->assertSame('' . ($this->time - 86500), $request->getCurrentTimestamp()); + $this->assertSame(($this->time - 86500), $request->getCurrentTimestamp()); } public function test_cdt_ShouldReturnTheCustomTimestamp_IfTimestampIsInFuture() |