serbanghita / Mobile-Detect

Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.
http://mobiledetect.net
MIT License
10.55k stars 2.68k forks source link

Fix: #857 and #876 #885

Closed darapa1 closed 2 years ago

darapa1 commented 2 years ago

Complete fix for Issue https://github.com/serbanghita/Mobile-Detect/issues/857 (see comments of the issue). Additional fix for "deprecated messages in PHP8.1" (https://github.com/serbanghita/Mobile-Detect/issues/876)

darapa1 commented 2 years ago

@serbanghita could you verify and apply the changes? Thanks!

serbanghita commented 2 years ago

@darapa1 have you ran some tests on this? I added this as a top priority in my queue

darapa1 commented 2 years ago

@serbanghita test was now working. I rolled back the fix for #858

Now all tests are successful.

In my point of view it would be much better to have the AndroidOS check with "Android.*Mobile" instead of only "Android" Unknown Tables will be detected as Desktop. Any real mobile phone will have "Mobile" in the US string and will be detected as isMobile.

But this can be discussed in a different thread. Most important are the other two issue we can fix with this PR.

kind regards

vicos59 commented 2 years ago

Just tried on a Samsung SM-T510.

Firefox: isMobile = true isTablet = false

Brave: isMobile = false isTablet = false

Verified that 'Desktop' mode is not enabled.

darapa1 commented 2 years ago

@vicos59 I just updated the regex for AndroidOS to have the old version back. I removed the changes for #858 as there are some more things to clarify.

serbanghita commented 2 years ago

@darapa1 ok, all tests pass, I'll release this fix

user@DESKTOP-DORM MINGW64 /d/webserver/www/git/Mobile-Detect (5.x)
$ vendor/bin/phpunit -v -c tests/phpunit.xml --coverage-text --strict-coverage --stop-on-risky
 PHPUnit 5.7.27 by Sebastian Bergmann and contributors.

Runtime:       PHP 5.6.40
Configuration: D:\webserver\www\git\Mobile-Detect\tests\phpunit.xml
Error:         No code coverage driver is available

.............................................................   61 / 1673 (  3%)
.............................................................  122 / 1673 (  7%)
.............................................................  183 / 1673 ( 10%)
.............................................................  244 / 1673 ( 14%)
.............................................................  305 / 1673 ( 18%)
.............................................................  366 / 1673 ( 21%)
.............................................................  427 / 1673 ( 25%)
.............................................................  488 / 1673 ( 29%)
.............................................................  549 / 1673 ( 32%)
.............................................................  610 / 1673 ( 36%)
.............................................................  671 / 1673 ( 40%)
.............................................................  732 / 1673 ( 43%)
.............................................................  793 / 1673 ( 47%)
.............................................................  854 / 1673 ( 51%)
.............................................................  915 / 1673 ( 54%)
.............................................................  976 / 1673 ( 58%)
............................................................. 1037 / 1673 ( 61%)
............................................................. 1098 / 1673 ( 65%)
............................................................. 1159 / 1673 ( 69%)
............................................................. 1220 / 1673 ( 72%)
............................................................. 1281 / 1673 ( 76%)
............................................................. 1342 / 1673 ( 80%)
............................................................. 1403 / 1673 ( 83%)
............................................................. 1464 / 1673 ( 87%)
............................................................. 1525 / 1673 ( 91%)
............................................................. 1586 / 1673 ( 94%)
............................................................. 1647 / 1673 ( 98%)
..........................                                    1673 / 1673 (100%)

Time: 8.59 seconds, Memory: 10.25MB

OK (1673 tests, 3919 assertions)