Skip to content

Commit d133e68

Browse files
committed
Remove support for hex number from is_numeric_string
1 parent 14d6de9 commit d133e68

16 files changed

+53
-134
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
. Removed support for assigning the result of new by reference. (Nikita)
4343
. Invalid octal literals in source code now produce compile errors, fixes PHPSadness #31. (Andrea)
4444
. Removed dl() function on fpm-fcgi. (Nikita)
45+
. Removed support for hexadecimal numeric strings. (Nikita)
4546

4647
- Date:
4748
. Fixed day_of_week function as it could sometimes return negative values

UPGRADING

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ PHP X.Y UPGRADE NOTES
6767
PHPSadness #31. Previously, the invalid digits (and any following valid
6868
digits) were simply ignored, such that 0781 became 7.
6969
. Removed dl() function on fpm-fcgi.
70+
. Removed support for hexadecimal numeric strings. This means that some
71+
operations like == will no longer specially interpret strings containing
72+
hexadecimal numbers. Furthermore is_numeric() will not consider hexadecimal
73+
strings to be numeric (use FILTER_VALIDATE_INT instead).
74+
(RFC: https://wiki.php.net/rfc/remove_hex_support_in_numeric_strings)
7075

7176
- Date:
7277
. Removed $is_dst parameter from mktime() and gmmktime().

Zend/zend_operators.c

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,7 +2664,7 @@ ZEND_API zend_uchar is_numeric_str_function(const zend_string *str, zend_long *l
26642664
ZEND_API zend_uchar _is_numeric_string_ex(const char *str, size_t length, zend_long *lval, double *dval, int allow_errors, int *oflow_info) /* {{{ */
26652665
{
26662666
const char *ptr;
2667-
int base = 10, digits = 0, dp_or_e = 0;
2667+
int digits = 0, dp_or_e = 0;
26682668
double local_dval = 0.0;
26692669
zend_uchar type;
26702670

@@ -2689,13 +2689,6 @@ ZEND_API zend_uchar _is_numeric_string_ex(const char *str, size_t length, zend_l
26892689
}
26902690

26912691
if (ZEND_IS_DIGIT(*ptr)) {
2692-
/* Handle hex numbers
2693-
* str is used instead of ptr to disallow signs and keep old behavior */
2694-
if (length > 2 && *str == '0' && (str[1] == 'x' || str[1] == 'X')) {
2695-
base = 16;
2696-
ptr += 2;
2697-
}
2698-
26992692
/* Skip any leading 0s */
27002693
while (*ptr == '0') {
27012694
ptr++;
@@ -2706,42 +2699,30 @@ ZEND_API zend_uchar _is_numeric_string_ex(const char *str, size_t length, zend_l
27062699
* a full match, stop when there are too many digits for a long */
27072700
for (type = IS_LONG; !(digits >= MAX_LENGTH_OF_LONG && (dval || allow_errors == 1)); digits++, ptr++) {
27082701
check_digits:
2709-
if (ZEND_IS_DIGIT(*ptr) || (base == 16 && ZEND_IS_XDIGIT(*ptr))) {
2702+
if (ZEND_IS_DIGIT(*ptr)) {
27102703
continue;
2711-
} else if (base == 10) {
2712-
if (*ptr == '.' && dp_or_e < 1) {
2713-
goto process_double;
2714-
} else if ((*ptr == 'e' || *ptr == 'E') && dp_or_e < 2) {
2715-
const char *e = ptr + 1;
2704+
} else if (*ptr == '.' && dp_or_e < 1) {
2705+
goto process_double;
2706+
} else if ((*ptr == 'e' || *ptr == 'E') && dp_or_e < 2) {
2707+
const char *e = ptr + 1;
27162708

2717-
if (*e == '-' || *e == '+') {
2718-
ptr = e++;
2719-
}
2720-
if (ZEND_IS_DIGIT(*e)) {
2721-
goto process_double;
2722-
}
2709+
if (*e == '-' || *e == '+') {
2710+
ptr = e++;
2711+
}
2712+
if (ZEND_IS_DIGIT(*e)) {
2713+
goto process_double;
27232714
}
27242715
}
27252716

27262717
break;
27272718
}
27282719

2729-
if (base == 10) {
2730-
if (digits >= MAX_LENGTH_OF_LONG) {
2731-
if (oflow_info != NULL) {
2732-
*oflow_info = *str == '-' ? -1 : 1;
2733-
}
2734-
dp_or_e = -1;
2735-
goto process_double;
2736-
}
2737-
} else if (!(digits < SIZEOF_ZEND_LONG * 2 || (digits == SIZEOF_ZEND_LONG * 2 && ptr[-digits] <= '7'))) {
2738-
if (dval) {
2739-
local_dval = zend_hex_strtod(str, &ptr);
2740-
}
2720+
if (digits >= MAX_LENGTH_OF_LONG) {
27412721
if (oflow_info != NULL) {
2742-
*oflow_info = 1;
2722+
*oflow_info = *str == '-' ? -1 : 1;
27432723
}
2744-
type = IS_DOUBLE;
2724+
dp_or_e = -1;
2725+
goto process_double;
27452726
}
27462727
} else if (*ptr == '.' && ZEND_IS_DIGIT(ptr[1])) {
27472728
process_double:
@@ -2785,7 +2766,7 @@ ZEND_API zend_uchar _is_numeric_string_ex(const char *str, size_t length, zend_l
27852766
}
27862767

27872768
if (lval) {
2788-
*lval = ZEND_STRTOL(str, NULL, base);
2769+
*lval = ZEND_STRTOL(str, NULL, 10);
27892770
}
27902771

27912772
return IS_LONG;

ext/standard/tests/array/array_udiff_assoc_variation.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ include('compare_function.inc');
1414
$key_compare_function = 'compare_function';
1515

1616
// Initialise all required variables
17-
$arr1 = array("one" => "one", "02" => "two", '3' => "three", "four", "0.5" => 5, 6.0 => 6, "seven" => "0x7");
17+
$arr1 = array("one" => "one", "02" => "two", '3' => "three", "four", "0.5" => 5, 6.0 => 6, "seven" => "07");
1818
$arr2 = array("one" => "one", "02" => "two", '3' => "three");
1919
$arr3 = array("four", "0.5" => "five", 6 => 6, "seven" => 7);
2020
$arr4 = array("four", "0.5" => "five", 6 => 6, "seven" => 7);

ext/standard/tests/general_functions/is_numeric.phpt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ $numerics = array(
8080
' 1',
8181
'2974394749328742328432',
8282
'-1e-2',
83-
"0xff",
84-
'0xff',
8583
"0123",
8684
'0123',
8785
"-0123",
@@ -109,6 +107,7 @@ unset ($unset_var);
109107

110108
// other types in a array
111109
$not_numerics = array(
110+
"0x80001",
112111
"-0x80001",
113112
"+0x80001",
114113
"-0x80001.5",
@@ -314,10 +313,6 @@ bool(true)
314313
bool(true)
315314
-- Iteration 76 --
316315
bool(true)
317-
-- Iteration 77 --
318-
bool(true)
319-
-- Iteration 78 --
320-
bool(true)
321316

322317
*** Testing is_numeric() on non numeric types ***
323318
-- Iteration 1 --
@@ -376,6 +371,8 @@ bool(false)
376371
bool(false)
377372
-- Iteration 28 --
378373
bool(false)
374+
-- Iteration 29 --
375+
bool(false)
379376

380377
*** Testing error conditions ***
381378

ext/standard/tests/math/ceil_basic.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ $values = array(0,
3131
"3.95E3",
3232
"-3.95E3",
3333
"039",
34-
"0x5F",
3534
true,
3635
false,
3736
null,
@@ -63,7 +62,6 @@ float(-10)
6362
float(3950)
6463
float(-3950)
6564
float(39)
66-
float(95)
6765
float(1)
6866
float(0)
6967
float(0)

ext/standard/tests/math/exp_basic.phpt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ $values = array(10,
1313
"3950.5",
1414
"3.9505e3",
1515
"039",
16-
"0x5F",
1716
true,
1817
false,
1918
null,
@@ -58,14 +57,11 @@ float(INF)
5857
float(8.6593400423994E+16)
5958

6059
-- Iteration 10 --
61-
float(1.811239082889E+41)
62-
63-
-- Iteration 11 --
6460
float(2.718281828459)
6561

66-
-- Iteration 12 --
62+
-- Iteration 11 --
6763
float(1)
6864

69-
-- Iteration 13 --
65+
-- Iteration 12 --
7066
float(1)
71-
===Done===
67+
===Done===

ext/standard/tests/math/expm1_basic.phpt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ $values = array(10,
2020
"3950.5",
2121
"3.9505e3",
2222
"039",
23-
"0x5F",
2423
true,
2524
false,
2625
null,
@@ -66,14 +65,11 @@ float(INF)
6665
float(8.6593400423994E+16)
6766

6867
-- Iteration 10 --
69-
float(1.811239082889E+41)
70-
71-
-- Iteration 11 --
7268
float(1.718281828459)
7369

74-
-- Iteration 12 --
70+
-- Iteration 11 --
7571
float(0)
7672

77-
-- Iteration 13 --
73+
-- Iteration 12 --
7874
float(0)
79-
===Done===
75+
===Done===

ext/standard/tests/math/floor_basic.phpt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ $values = array(0,
2727
"3.95E3",
2828
"-3.95E3",
2929
"039",
30-
"0x5F",
3130
true,
3231
false,
3332
null,
@@ -94,9 +93,6 @@ float(-3950)
9493
-- floor 039 --
9594
float(39)
9695

97-
-- floor 0x5F --
98-
float(95)
99-
10096
-- floor 1 --
10197
float(1)
10298

@@ -105,4 +101,4 @@ float(0)
105101

106102
-- floor --
107103
float(0)
108-
===Done===
104+
===Done===

ext/standard/tests/math/mt_rand_basic.phpt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,13 @@ $min = array(true,
5656
false,
5757
null,
5858
"10",
59-
"0x10",
6059
"10.5");
6160

62-
// Eexepcted numerical equivalent of above non-numerics
61+
// Expected numerical equivalent of above non-numerics
6362
$minval = array(1,
6463
0,
6564
0,
6665
10,
67-
0,
6866
10);
6967
for ($x = 0; $x < count($min); $x++) {
7068
for ($i = 0; $i < 100; $i++) {
@@ -98,5 +96,4 @@ PASSED range min = 1 max = 100
9896
PASSED range min = 0 max = 100
9997
PASSED range min = 0 max = 100
10098
PASSED range min = 10 max = 100
101-
PASSED range min = 0 max = 100
10299
PASSED range min = 10 max = 100

0 commit comments

Comments
 (0)