Skip to content

Commit 2139918

Browse files
committed
Fix #65550: get_browser() incorrectly parsers entries with "+" sign
+ signs in the browscap patterns are meant to be literal characters, so we have to escape them for the regex matching.
1 parent 84512a1 commit 2139918

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ PHP NEWS
4444
- Standard:
4545
. Fixed bug #72823 (strtr out-of-bound access). (cmb)
4646
. Fixed bug #72278 (getimagesize returning FALSE on valid jpg). (cmb)
47+
. Fixed bug #65550 (get_browser() incorrectly parses entries with "+" sign).
48+
(cmb)
4749

4850
- XML:
4951
. Fixed bug #72085 (SEGV on unknown address zif_xml_parse). (cmb)

ext/standard/browscap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ static void convert_browscap_pattern(zval *pattern, int persistent) /* {{{ */
123123
t[j++] = '\\';
124124
t[j] = '~';
125125
break;
126+
case '+':
127+
t[j++] = '\\';
128+
t[j] = '+';
129+
break;
126130
default:
127131
t[j] = Z_STRVAL_P(pattern)[i];
128132
break;

ext/standard/tests/misc/bug65550.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #65550 (get_browser() incorrectly parses entries with "+" sign)
3+
--INI--
4+
browscap={PWD}/browscap.ini
5+
--SKIPIF--
6+
<?php
7+
if (!is_readable(ini_get('browscap'))) die('skip browscap.ini file ' . ini_get('browscap') . ' not readable');
8+
?>
9+
--FILE--
10+
<?php
11+
$user_agent = 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US) AppleWebKit/522+ (KHTML, like Gecko, Safari/522) OmniWeb/v613';
12+
$caps = get_browser($user_agent, true);
13+
var_dump($caps['browser'], $caps['version']);
14+
?>
15+
==DONE==
16+
--EXPECT--
17+
string(7) "OmniWeb"
18+
string(3) "5.6"
19+
==DONE==

0 commit comments

Comments
 (0)