-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bug] No user-agent has been set #946
- Loading branch information
1 parent
80607ae
commit 4921892
Showing
5 changed files
with
84 additions
and
33 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
services: | ||
setup: | ||
image: composer:latest | ||
command: > | ||
/bin/sh -c " | ||
rm -rf vendor && | ||
rm -f composer.lock composer.phar && | ||
set -xe && composer install && | ||
composer -v && | ||
ls -al" | ||
working_dir: /app | ||
volumes: | ||
- .:/app | ||
|
||
runUnitTests: | ||
image: php:8.0.3-fpm-alpine3.13 | ||
working_dir: /app | ||
command: > | ||
/bin/sh -c "vendor/bin/phpunit -v -c tests/phpunit.xml --coverage-text --strict-coverage --stop-on-risky" | ||
ports: | ||
- "8000:8000" | ||
volumes: | ||
- .:/app | ||
|
||
runLinting: | ||
image: php:8.0.3-fpm-alpine3.13 | ||
working_dir: /app | ||
command: > | ||
/bin/sh -c "vendor/bin/phpcs; vendor/bin/phpcbf" | ||
ports: | ||
- "8000:8000" | ||
volumes: | ||
- .:/app | ||
|
||
generateModel: | ||
image: php:8.0.3-fpm-alpine3.13 | ||
working_dir: /app | ||
command: > | ||
/bin/sh -c "php ./scripts/export_to_json.php" | ||
ports: | ||
- "8000:8000" | ||
volumes: | ||
- .:/app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
* @author Nick Ilyin <[email protected]> | ||
* @author: Victor Stanciu <[email protected]> (original author) | ||
* | ||
* @version 4.8.03 | ||
* @version 4.8.04 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
@@ -236,7 +236,7 @@ class MobileDetect | |
/** | ||
* Stores the version number of the current release. | ||
*/ | ||
protected string $VERSION = '4.8.03'; | ||
protected string $VERSION = '4.8.04'; | ||
|
||
protected array $config = [ | ||
// Auto-initialization on HTTP headers from $_SERVER['HTTP...'] | ||
|
@@ -1210,12 +1210,12 @@ private function prepareUserAgent(string $userAgent): string | |
* Set the User-Agent to be used. | ||
* | ||
* @param string $userAgent The User-Agent string. | ||
* @return string|null | ||
* @return string | ||
*/ | ||
public function setUserAgent(string $userAgent): string|null | ||
public function setUserAgent(string $userAgent): string | ||
{ | ||
$preparedUserAgent = $this->prepareUserAgent($userAgent); | ||
return $this->userAgent = !empty($preparedUserAgent) ? $preparedUserAgent : null; | ||
return $this->userAgent = $preparedUserAgent; | ||
} | ||
|
||
/** | ||
|
@@ -1230,7 +1230,12 @@ public function getUserAgent(): ?string | |
|
||
public function hasUserAgent(): bool | ||
{ | ||
return \is_string($this->userAgent) && !empty($this->userAgent); | ||
return is_string($this->userAgent); | ||
} | ||
|
||
public function isUserAgentEmpty(): bool | ||
{ | ||
return $this->hasUserAgent() && $this->userAgent === ''; | ||
} | ||
|
||
public function getMatchingRegex(): ?string | ||
|
@@ -1366,7 +1371,11 @@ public function __call(string $name, array $arguments) | |
public function isMobile(): bool | ||
{ | ||
if (!$this->hasUserAgent()) { | ||
throw new MobileDetectException('No user-agent has been set.'); | ||
throw new MobileDetectException('No valid user-agent has been set.'); | ||
} | ||
|
||
if ($this->isUserAgentEmpty()) { | ||
return false; | ||
} | ||
|
||
// Cache check. | ||
|
@@ -1411,6 +1420,10 @@ public function isTablet(): bool | |
throw new MobileDetectException('No user-agent has been set.'); | ||
} | ||
|
||
if ($this->isUserAgentEmpty()) { | ||
return false; | ||
} | ||
|
||
// Cache check. | ||
try { | ||
$cacheKey = $this->createCacheKey("tablet"); | ||
|
@@ -1476,6 +1489,10 @@ public function is(string $ruleName): bool | |
throw new MobileDetectException('No user-agent has been set.'); | ||
} | ||
|
||
if ($this->isUserAgentEmpty()) { | ||
return false; | ||
} | ||
|
||
// Cache check. | ||
try { | ||
$cacheKey = $this->createCacheKey($ruleName); | ||
|
@@ -1671,7 +1688,7 @@ public static function flattenHeaders(array $httpHeaders): string | |
{ | ||
$key = ''; | ||
foreach ($httpHeaders as $name => $value) { | ||
$key .= "$name: $value" . "\n"; | ||
$key .= "$name: $value" . PHP_EOL; | ||
} | ||
return trim($key); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters