-
-
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.
MobileDetect by default will not throw an exception if UserAgent is n…
…ot set. By default "autoInitOfHttpHeaders" is "true", and if UserAgent is not found, it will be set to empty string "" #946 (comment)
- Loading branch information
1 parent
ae8a4bc
commit b7a8cdd
Showing
4 changed files
with
38 additions
and
7 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version": "4.8.04", | ||
"version": "4.8.05", | ||
"headerMatch": { | ||
"HTTP_ACCEPT": { | ||
"matches": [ | ||
|
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
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.04 | ||
* @version 4.8.05 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
@@ -236,7 +236,7 @@ class MobileDetect | |
/** | ||
* Stores the version number of the current release. | ||
*/ | ||
protected string $VERSION = '4.8.04'; | ||
protected string $VERSION = '4.8.05'; | ||
|
||
protected array $config = [ | ||
// Auto-initialization on HTTP headers from $_SERVER['HTTP...'] | ||
|
@@ -1033,6 +1033,8 @@ public function __construct( | |
// Override config from user. | ||
$this->config = array_merge($this->config, $config); | ||
|
||
// Beware that if you use "autoInitOfHttpHeaders: false" and you forget to setUserAgent | ||
// to something other than a string, an MobileDetectException exception will be thrown. | ||
if ($this->config['autoInitOfHttpHeaders']) { | ||
$this->autoInitKnownHttpHeaders(); | ||
} | ||
|
@@ -1077,6 +1079,12 @@ public function autoInitKnownHttpHeaders(): void | |
} | ||
} | ||
$this->setHttpHeaders($httpHeaders); | ||
|
||
// Set the User-Agent even if it's an empty string so that "autoInitOfHttpHeaders" doesn't throw an exception. | ||
// https://github.com/serbanghita/Mobile-Detect/issues/946#issuecomment-1885675939 | ||
if (!$this->hasUserAgent()) { | ||
$this->setUserAgent(""); | ||
} | ||
} | ||
|
||
/** | ||
|
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