Browse Source

Remove support for hex number from is_numeric_string

pull/780/merge
Nikita Popov 14 years ago
parent
commit
d133e68bab
  1. 1
      NEWS
  2. 5
      UPGRADING
  3. 51
      Zend/zend_operators.c
  4. 2
      ext/standard/tests/array/array_udiff_assoc_variation.phpt
  5. 9
      ext/standard/tests/general_functions/is_numeric.phpt
  6. 2
      ext/standard/tests/math/ceil_basic.phpt
  7. 10
      ext/standard/tests/math/exp_basic.phpt
  8. 10
      ext/standard/tests/math/expm1_basic.phpt
  9. 6
      ext/standard/tests/math/floor_basic.phpt
  10. 5
      ext/standard/tests/math/mt_rand_basic.phpt
  11. 3
      ext/standard/tests/math/rand_basic.phpt
  12. 29
      ext/standard/tests/math/round_basic.phpt
  13. 18
      ext/standard/tests/strings/hebrev_variation2.phpt
  14. 30
      ext/standard/tests/strings/hebrevc_variation2.phpt
  15. 2
      ext/standard/tests/strings/money_format_variation2.phpt
  16. 4
      ext/standard/tests/strings/str_pad_variation4.phpt

1
NEWS

@ -42,6 +42,7 @@
. Removed support for assigning the result of new by reference. (Nikita)
. Invalid octal literals in source code now produce compile errors, fixes PHPSadness #31. (Andrea)
. Removed dl() function on fpm-fcgi. (Nikita)
. Removed support for hexadecimal numeric strings. (Nikita)
- Date:
. Fixed day_of_week function as it could sometimes return negative values

5
UPGRADING

@ -67,6 +67,11 @@ PHP X.Y UPGRADE NOTES
PHPSadness #31. Previously, the invalid digits (and any following valid
digits) were simply ignored, such that 0781 became 7.
. Removed dl() function on fpm-fcgi.
. Removed support for hexadecimal numeric strings. This means that some
operations like == will no longer specially interpret strings containing
hexadecimal numbers. Furthermore is_numeric() will not consider hexadecimal
strings to be numeric (use FILTER_VALIDATE_INT instead).
(RFC: https://wiki.php.net/rfc/remove_hex_support_in_numeric_strings)
- Date:
. Removed $is_dst parameter from mktime() and gmmktime().

51
Zend/zend_operators.c

@ -2664,7 +2664,7 @@ ZEND_API zend_uchar is_numeric_str_function(const zend_string *str, zend_long *l
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) /* {{{ */
{
const char *ptr;
int base = 10, digits = 0, dp_or_e = 0;
int digits = 0, dp_or_e = 0;
double local_dval = 0.0;
zend_uchar type;
@ -2689,13 +2689,6 @@ ZEND_API zend_uchar _is_numeric_string_ex(const char *str, size_t length, zend_l
}
if (ZEND_IS_DIGIT(*ptr)) {
/* Handle hex numbers
* str is used instead of ptr to disallow signs and keep old behavior */
if (length > 2 && *str == '0' && (str[1] == 'x' || str[1] == 'X')) {
base = 16;
ptr += 2;
}
/* Skip any leading 0s */
while (*ptr == '0') {
ptr++;
@ -2706,42 +2699,30 @@ ZEND_API zend_uchar _is_numeric_string_ex(const char *str, size_t length, zend_l
* a full match, stop when there are too many digits for a long */
for (type = IS_LONG; !(digits >= MAX_LENGTH_OF_LONG && (dval || allow_errors == 1)); digits++, ptr++) {
check_digits:
if (ZEND_IS_DIGIT(*ptr) || (base == 16 && ZEND_IS_XDIGIT(*ptr))) {
if (ZEND_IS_DIGIT(*ptr)) {
continue;
} else if (base == 10) {
if (*ptr == '.' && dp_or_e < 1) {
goto process_double;
} else if ((*ptr == 'e' || *ptr == 'E') && dp_or_e < 2) {
const char *e = ptr + 1;
} else if (*ptr == '.' && dp_or_e < 1) {
goto process_double;
} else if ((*ptr == 'e' || *ptr == 'E') && dp_or_e < 2) {
const char *e = ptr + 1;
if (*e == '-' || *e == '+') {
ptr = e++;
}
if (ZEND_IS_DIGIT(*e)) {
goto process_double;
}
if (*e == '-' || *e == '+') {
ptr = e++;
}
if (ZEND_IS_DIGIT(*e)) {
goto process_double;
}
}
break;
}
if (base == 10) {
if (digits >= MAX_LENGTH_OF_LONG) {
if (oflow_info != NULL) {
*oflow_info = *str == '-' ? -1 : 1;
}
dp_or_e = -1;
goto process_double;
}
} else if (!(digits < SIZEOF_ZEND_LONG * 2 || (digits == SIZEOF_ZEND_LONG * 2 && ptr[-digits] <= '7'))) {
if (dval) {
local_dval = zend_hex_strtod(str, &ptr);
}
if (digits >= MAX_LENGTH_OF_LONG) {
if (oflow_info != NULL) {
*oflow_info = 1;
*oflow_info = *str == '-' ? -1 : 1;
}
type = IS_DOUBLE;
dp_or_e = -1;
goto process_double;
}
} else if (*ptr == '.' && ZEND_IS_DIGIT(ptr[1])) {
process_double:
@ -2785,7 +2766,7 @@ process_double:
}
if (lval) {
*lval = ZEND_STRTOL(str, NULL, base);
*lval = ZEND_STRTOL(str, NULL, 10);
}
return IS_LONG;

2
ext/standard/tests/array/array_udiff_assoc_variation.phpt

@ -14,7 +14,7 @@ include('compare_function.inc');
$key_compare_function = 'compare_function';
// Initialise all required variables
$arr1 = array("one" => "one", "02" => "two", '3' => "three", "four", "0.5" => 5, 6.0 => 6, "seven" => "0x7");
$arr1 = array("one" => "one", "02" => "two", '3' => "three", "four", "0.5" => 5, 6.0 => 6, "seven" => "07");
$arr2 = array("one" => "one", "02" => "two", '3' => "three");
$arr3 = array("four", "0.5" => "five", 6 => 6, "seven" => 7);
$arr4 = array("four", "0.5" => "five", 6 => 6, "seven" => 7);

9
ext/standard/tests/general_functions/is_numeric.phpt

@ -80,8 +80,6 @@ $numerics = array(
' 1',
'2974394749328742328432',
'-1e-2',
"0xff",
'0xff',
"0123",
'0123',
"-0123",
@ -109,6 +107,7 @@ unset ($unset_var);
// other types in a array
$not_numerics = array(
"0x80001",
"-0x80001",
"+0x80001",
"-0x80001.5",
@ -314,10 +313,6 @@ bool(true)
bool(true)
-- Iteration 76 --
bool(true)
-- Iteration 77 --
bool(true)
-- Iteration 78 --
bool(true)
*** Testing is_numeric() on non numeric types ***
-- Iteration 1 --
@ -376,6 +371,8 @@ bool(false)
bool(false)
-- Iteration 28 --
bool(false)
-- Iteration 29 --
bool(false)
*** Testing error conditions ***

2
ext/standard/tests/math/ceil_basic.phpt

@ -31,7 +31,6 @@ $values = array(0,
"3.95E3",
"-3.95E3",
"039",
"0x5F",
true,
false,
null,
@ -63,7 +62,6 @@ float(-10)
float(3950)
float(-3950)
float(39)
float(95)
float(1)
float(0)
float(0)

10
ext/standard/tests/math/exp_basic.phpt

@ -13,7 +13,6 @@ $values = array(10,
"3950.5",
"3.9505e3",
"039",
"0x5F",
true,
false,
null,
@ -58,14 +57,11 @@ float(INF)
float(8.6593400423994E+16)
-- Iteration 10 --
float(1.811239082889E+41)
-- Iteration 11 --
float(2.718281828459)
-- Iteration 12 --
-- Iteration 11 --
float(1)
-- Iteration 13 --
-- Iteration 12 --
float(1)
===Done===
===Done===

10
ext/standard/tests/math/expm1_basic.phpt

@ -20,7 +20,6 @@ $values = array(10,
"3950.5",
"3.9505e3",
"039",
"0x5F",
true,
false,
null,
@ -66,14 +65,11 @@ float(INF)
float(8.6593400423994E+16)
-- Iteration 10 --
float(1.811239082889E+41)
-- Iteration 11 --
float(1.718281828459)
-- Iteration 12 --
-- Iteration 11 --
float(0)
-- Iteration 13 --
-- Iteration 12 --
float(0)
===Done===
===Done===

6
ext/standard/tests/math/floor_basic.phpt

@ -27,7 +27,6 @@ $values = array(0,
"3.95E3",
"-3.95E3",
"039",
"0x5F",
true,
false,
null,
@ -94,9 +93,6 @@ float(-3950)
-- floor 039 --
float(39)
-- floor 0x5F --
float(95)
-- floor 1 --
float(1)
@ -105,4 +101,4 @@ float(0)
-- floor --
float(0)
===Done===
===Done===

5
ext/standard/tests/math/mt_rand_basic.phpt

@ -56,15 +56,13 @@ $min = array(true,
false,
null,
"10",
"0x10",
"10.5");
// Eexepcted numerical equivalent of above non-numerics
// Expected numerical equivalent of above non-numerics
$minval = array(1,
0,
0,
10,
0,
10);
for ($x = 0; $x < count($min); $x++) {
for ($i = 0; $i < 100; $i++) {
@ -98,5 +96,4 @@ PASSED range min = 1 max = 100
PASSED range min = 0 max = 100
PASSED range min = 0 max = 100
PASSED range min = 10 max = 100
PASSED range min = 0 max = 100
PASSED range min = 10 max = 100

3
ext/standard/tests/math/rand_basic.phpt

@ -56,7 +56,6 @@ $min = array(true,
false,
null,
"10",
"0x10",
"10.5");
// Eexepcted numerical equivalent of above non-numerics
@ -64,7 +63,6 @@ $minval = array(1,
0,
0,
10,
0,
10);
for ($x = 0; $x < count($min); $x++) {
for ($i = 0; $i < 100; $i++) {
@ -99,5 +97,4 @@ PASSED range min = 1 max = 100
PASSED range min = 0 max = 100
PASSED range min = 0 max = 100
PASSED range min = 10 max = 100
PASSED range min = 0 max = 100
PASSED range min = 10 max = 100

29
ext/standard/tests/math/round_basic.phpt

@ -20,8 +20,7 @@ $values = array(123456789,
0x234567,
067777777,
"1.234567",
"2.3456789e8",
"0x1234CDEF");
"2.3456789e8");
$precision = array(2,
8,
@ -29,7 +28,6 @@ $precision = array(2,
04,
3.6,
"2",
"0x03",
"04",
"3.6",
"2.1e1",
@ -56,7 +54,6 @@ round: 123456789
...with precision 4-> float(123456789)
...with precision 3.6-> float(123456789)
...with precision 2-> float(123456789)
...with precision 0x03-> float(123456789)
...with precision 04-> float(123456789)
...with precision 3.6-> float(123456789)
...with precision 2.1e1-> float(123456789)
@ -70,7 +67,6 @@ round: 123.456789
...with precision 4-> float(123.4568)
...with precision 3.6-> float(123.457)
...with precision 2-> float(123.46)
...with precision 0x03-> float(123.457)
...with precision 04-> float(123.4568)
...with precision 3.6-> float(123.457)
...with precision 2.1e1-> float(123.456789)
@ -84,7 +80,6 @@ round: -4.5679123
...with precision 4-> float(-4.5679)
...with precision 3.6-> float(-4.568)
...with precision 2-> float(-4.57)
...with precision 0x03-> float(-4.568)
...with precision 04-> float(-4.5679)
...with precision 3.6-> float(-4.568)
...with precision 2.1e1-> float(-4.5679123)
@ -98,7 +93,6 @@ round: 12300
...with precision 4-> float(12300)
...with precision 3.6-> float(12300)
...with precision 2-> float(12300)
...with precision 0x03-> float(12300)
...with precision 04-> float(12300)
...with precision 3.6-> float(12300)
...with precision 2.1e1-> float(12300)
@ -112,7 +106,6 @@ round: -4567
...with precision 4-> float(-4567)
...with precision 3.6-> float(-4567)
...with precision 2-> float(-4567)
...with precision 0x03-> float(-4567)
...with precision 04-> float(-4567)
...with precision 3.6-> float(-4567)
...with precision 2.1e1-> float(-4567)
@ -126,7 +119,6 @@ round: 2311527
...with precision 4-> float(2311527)
...with precision 3.6-> float(2311527)
...with precision 2-> float(2311527)
...with precision 0x03-> float(2311527)
...with precision 04-> float(2311527)
...with precision 3.6-> float(2311527)
...with precision 2.1e1-> float(2311527)
@ -140,7 +132,6 @@ round: 14680063
...with precision 4-> float(14680063)
...with precision 3.6-> float(14680063)
...with precision 2-> float(14680063)
...with precision 0x03-> float(14680063)
...with precision 04-> float(14680063)
...with precision 3.6-> float(14680063)
...with precision 2.1e1-> float(14680063)
@ -154,7 +145,6 @@ round: 1.234567
...with precision 4-> float(1.2346)
...with precision 3.6-> float(1.235)
...with precision 2-> float(1.23)
...with precision 0x03-> float(1.235)
...with precision 04-> float(1.2346)
...with precision 3.6-> float(1.235)
...with precision 2.1e1-> float(1.234567)
@ -168,25 +158,10 @@ round: 2.3456789e8
...with precision 4-> float(234567890)
...with precision 3.6-> float(234567890)
...with precision 2-> float(234567890)
...with precision 0x03-> float(234567890)
...with precision 04-> float(234567890)
...with precision 3.6-> float(234567890)
...with precision 2.1e1-> float(234567890)
...with precision -> float(234567890)
...with precision 1-> float(234567890)
...with precision -> float(234567890)
round: 0x1234CDEF
...with precision 2-> float(305450479)
...with precision 8-> float(305450479)
...with precision 3-> float(305450479)
...with precision 4-> float(305450479)
...with precision 3.6-> float(305450479)
...with precision 2-> float(305450479)
...with precision 0x03-> float(305450479)
...with precision 04-> float(305450479)
...with precision 3.6-> float(305450479)
...with precision 2.1e1-> float(305450479)
...with precision -> float(305450479)
...with precision 1-> float(305450479)
...with precision -> float(305450479)
===Done===
===Done===

18
ext/standard/tests/strings/hebrev_variation2.phpt

@ -259,18 +259,10 @@ string(109) ".The hebrev function converts logical Hebrew text to visual text
.The function tries to avoid breaking words
"
-- Iteration 23 --
string(109) "textual vis
to
textrew Heb
icallog
ertsconvion unctf
brevhe
.Therds
wo
kingbreaoid av
to
riest
tionfuncThe .
Notice: A non well formed numeric value encountered in %s on line %d
string(109) ".The hebrev function converts logical Hebrew text to visual text
.The function tries to avoid breaking words
"
-- Iteration 24 --
@ -288,4 +280,4 @@ string(109) ".The hebrev function converts logical Hebrew text to visual text
string(109) ".The hebrev function converts logical Hebrew text to visual text
.The function tries to avoid breaking words
"
===DONE===
===DONE===

30
ext/standard/tests/strings/hebrevc_variation2.phpt

@ -381,29 +381,13 @@ string(241) ".The hebrevcc function converts logical Hebrew text to visual text<
.The function tries to avoid breaking words<br />
"
-- Iteration 23 --
string(349) "textual vis<br />
to<br />
textrew Heb<br />
icallog<br />
ertsconvion unctf<br />
evcchebrThe .<br />
inesnewlrts onvec<br />
it<br />
thatnce feredif<br />
the<br />
withc() brevhe<br />
to<br />
ilarsim<br />
is<br />
tionfunchis ) T<br />
(<br />
'<br<to .'<br />
<br />
ordsw<br />
kingbreaoid av<br />
to<br />
riest<br />
tionfuncThe .<br />
Notice: A non well formed numeric value encountered in %s on line %d
string(241) ".The hebrevcc function converts logical Hebrew text to visual text<br />
) This function is similar to hebrevc() with the difference that it converts newlines<br />
<to '<br (<br />
.'<br />
.The function tries to avoid breaking words<br />
"
-- Iteration 24 --

2
ext/standard/tests/strings/money_format_variation2.phpt

@ -156,6 +156,8 @@ NULL
Warning: money_format() expects parameter 2 to be float, string given in %s on line %d
NULL
-- Iteration 21 --
Notice: A non well formed numeric value encountered in %s on line %d
string
-- Iteration 22 --

4
ext/standard/tests/strings/str_pad_variation4.phpt

@ -132,7 +132,9 @@ NULL
-- Iteration 12 --
string(20) "****Test string*****"
-- Iteration 13 --
string(20) "****Test string*****"
Notice: A non well formed numeric value encountered in %s on line %d
string(20) "*********Test string"
-- Iteration 14 --
string(20) "****Test string*****"
-- Iteration 15 --

Loading…
Cancel
Save