Skip to content

Commit 8dc178c

Browse files
committed
Fixed bugs in versions::released() where it didn't always pick the earliest date for each browser based on the version number supplied.
Updated tests.
1 parent e03448d commit 8dc178c

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

src/helpers/versions.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ protected static function latest(array $versions, ?\DateTime $now = null) : ?str
7575
protected static function released(array $data, string $version) : ?string {
7676
$major = \intval($version);
7777
$len = 0;
78-
$i = 0;
7978
$vlen = \strlen($version);
8079
$released = null;
8180
foreach ($data AS $ver => $date) {
@@ -89,14 +88,13 @@ protected static function released(array $data, string $version) : ?string {
8988
break;
9089
}
9190
}
92-
if ($match > $len) {
91+
if ($match && $match > $len && ($released === null || $released > $date)) {
9392
$len = $match;
9493
$released = $date;
9594
}
9695
}
97-
$i++;
9896
}
99-
return $released !== null ? (new \DateTime(\strval($released)))->format('Y-m-d') : null;
97+
return !empty($released) ? (new \DateTime(\strval($released)))->format('Y-m-d') : null;
10098
}
10199

102100
public static function get(string $browser, string $version, array $config) : array {

tests/browsersTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ public function testBrave() : void {
500500
'engineversion' => '601.1.46',
501501
'browser' => 'Brave',
502502
'browserversion' => '1.2.11',
503-
'browserreleased' => '2025-08-13'
503+
'browserreleased' => '2025-08-26'
504504
],
505505
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_4_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Brave/115.0.0.0 Safari/605.1.15' => [
506506
'string' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_4_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Brave/115.0.0.0 Safari/605.1.15',
@@ -1335,7 +1335,7 @@ public function testOculusBrowser() : void {
13351335
'appversion' => '13.0.0.2.16.259832224',
13361336
'engine' => 'Blink',
13371337
'engineversion' => '87.0.4280.66',
1338-
'browserreleased' => '2020-11-17'
1338+
'browserreleased' => '2021-01-11'
13391339
],
13401340
'Mozilla/5.0 (Linux; Android 10; Quest) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/19.1.0.1.50.350517500 SamsungBrowser/4.0 Chrome/96.0.4664.174 Mobile VR Safari/537.36' => [
13411341
'string' => 'Mozilla/5.0 (Linux; Android 10; Quest) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/19.1.0.1.50.350517500 SamsungBrowser/4.0 Chrome/96.0.4664.174 Mobile VR Safari/537.36',
@@ -1353,7 +1353,7 @@ public function testOculusBrowser() : void {
13531353
'appversion' => '19.1.0.1.50.350517500',
13541354
'engine' => 'Blink',
13551355
'engineversion' => '96.0.4664.174',
1356-
'browserreleased' => '2021-12-13'
1356+
'browserreleased' => '2021-01-11'
13571357
],
13581358
'Mozilla/5.0 (Linux; Android 7.1.1; Pacific) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/9.2.0.2.122.217074189 SamsungBrowser/4.0 Chrome/81.0.4044.117 Mobile VR Safari/537.36' => [
13591359
'string' => 'Mozilla/5.0 (Linux; Android 7.1.1; Pacific) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/9.2.0.2.122.217074189 SamsungBrowser/4.0 Chrome/81.0.4044.117 Mobile VR Safari/537.36',
@@ -1371,7 +1371,7 @@ public function testOculusBrowser() : void {
13711371
'appversion' => '9.2.0.2.122.217074189',
13721372
'engine' => 'Blink',
13731373
'engineversion' => '81.0.4044.117',
1374-
'browserreleased' => '2020-04-15'
1374+
'browserreleased' => '2021-01-11'
13751375
]
13761376
];
13771377
foreach ($strings AS $ua => $item) {
@@ -1394,7 +1394,7 @@ public function testSamsungBrowser() : void {
13941394
'browserversion' => '19.0',
13951395
'engine' => 'Blink',
13961396
'engineversion' => '102.0.5005.125',
1397-
'browserreleased' => '2022-06-09'
1397+
'browserreleased' => '2023-01-07'
13981398
],
13991399
'Mozilla/5.0 (Linux; Android 8.1.0; SAMSUNG SM-A260G Build/OPR6; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 SamsungBrowser/7.2 Chrome/108.0.5359.128 Mobile Safari/537.36' => [
14001400
'string' => 'Mozilla/5.0 (Linux; Android 8.1.0; SAMSUNG SM-A260G Build/OPR6; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 SamsungBrowser/7.2 Chrome/108.0.5359.128 Mobile Safari/537.36',
@@ -1410,7 +1410,7 @@ public function testSamsungBrowser() : void {
14101410
'browserversion' => '7.2',
14111411
'engine' => 'Blink',
14121412
'engineversion' => '108.0.5359.128',
1413-
'browserreleased' => '2023-01-10'
1413+
'browserreleased' => '2018-06-26'
14141414
]
14151415
];
14161416
foreach ($strings AS $ua => $item) {

tests/categoriesTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function testTablet() : void {
165165
'app' => 'Facebook',
166166
'appname' => 'FB4A',
167167
'appversion' => '419.0.0.37.71',
168-
'browserreleased' => '2023-06-26'
168+
'browserreleased' => '2023-06-13'
169169
]
170170
];
171171
foreach ($strings AS $ua => $item) {
@@ -193,7 +193,7 @@ public function testVr() : void {
193193
'app' => 'Oculus Browser',
194194
'appname' => 'OculusBrowser',
195195
'appversion' => '25.3.0.4.30.438623098',
196-
'browserreleased' => '2023-01-10'
196+
'browserreleased' => '2021-01-11'
197197
]
198198
];
199199
foreach ($strings AS $ua => $item) {
@@ -309,7 +309,7 @@ public function testTv() : void {
309309
'engineversion' => '69.0.3497.106',
310310
'browser' => 'Samsung Internet',
311311
'browserversion' => '3.0',
312-
'browserreleased' => '2018-09-17'
312+
'browserreleased' => '2017-11-09'
313313
]
314314
];
315315
foreach ($strings AS $ua => $item) {

tests/crawlersTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,8 @@ public function testAds() : void {
757757
'browser' => 'Samsung Internet',
758758
'browserversion' => '3.3',
759759
'engine' => 'Blink',
760-
'engineversion' => '38.0.2125.102'
760+
'engineversion' => '38.0.2125.102',
761+
'browserreleased' => '2017-11-09'
761762
]
762763
];
763764
foreach ($strings AS $ua => $item) {

tests/platformsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ public function testX11() : void {
10681068
'engineversion' => '106.0.5249.181',
10691069
'architecture' => 'x86',
10701070
'bits' => 64,
1071-
'browserreleased' => '2022-10-25'
1071+
'browserreleased' => '2021-01-11'
10721072
],
10731073
'Mozilla/5.0 (X11; U; Linux x86_64; fr; rv:1.9.2.14pre) Gecko/20101224 Ubuntu/10.04 (lucid) Namoroka/3.6.14pre' => [
10741074
'string' => 'Mozilla/5.0 (X11; U; Linux x86_64; fr; rv:1.9.2.14pre) Gecko/20101224 Ubuntu/10.04 (lucid) Namoroka/3.6.14pre',

0 commit comments

Comments
 (0)