]> granicus.if.org Git - php/commitdiff
Remove support for hex number from is_numeric_string
authorNikita Popov <nikic@php.net>
Tue, 17 Apr 2012 13:45:53 +0000 (15:45 +0200)
committerNikita Popov <nikic@php.net>
Wed, 28 Jan 2015 21:54:17 +0000 (22:54 +0100)
16 files changed:
NEWS
UPGRADING
Zend/zend_operators.c
ext/standard/tests/array/array_udiff_assoc_variation.phpt
ext/standard/tests/general_functions/is_numeric.phpt
ext/standard/tests/math/ceil_basic.phpt
ext/standard/tests/math/exp_basic.phpt
ext/standard/tests/math/expm1_basic.phpt
ext/standard/tests/math/floor_basic.phpt
ext/standard/tests/math/mt_rand_basic.phpt
ext/standard/tests/math/rand_basic.phpt
ext/standard/tests/math/round_basic.phpt
ext/standard/tests/strings/hebrev_variation2.phpt
ext/standard/tests/strings/hebrevc_variation2.phpt
ext/standard/tests/strings/money_format_variation2.phpt
ext/standard/tests/strings/str_pad_variation4.phpt

diff --git a/NEWS b/NEWS
index 417c2ac3ee271fead7988039c90565b46ee3ad30..df072c82042891dade7866a6c2bb8503a8e9de46 100644 (file)
--- a/NEWS
+++ b/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
index 7c54f4167dd8ac9b0010aadf0e24e67e64e355d1..7cb958f7ab5f6ed44bad8d228d088fdb61dad047 100644 (file)
--- a/UPGRADING
+++ b/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().
index f178c34880e7131cdc38888252cace244e134848..76a3d31a8528542bb844760f9c93781f0d7904e6 100644 (file)
@@ -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;
index 84e8841b2c48cd9394a1193a2d519796810f4a0a..465c5008fd26b7ebda06a2ab06d9f9407dec2ca3 100644 (file)
@@ -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);
index 9857c94223be62546d0b40c443696c80c0821691..415ce069e96f12ccb44dfb5bf974e1f16356e0e8 100644 (file)
@@ -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 ***
 
index 679460533d63d04d8a0495aec7a388a1b1fc01e1..e90afd33886832194b014b2db6b8ea6c593f2d56 100644 (file)
@@ -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)
index 9526c66fa4af021bceaf62751bc614e9aaa55b90..135705507cf911af3ed6343f134ffba7c4e26508 100644 (file)
@@ -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===
\ No newline at end of file
+===Done===
index fa1d571db42babca06714da4c9e379cc599224db..320b01a27dd3cd0bf7cb883b97230770eac40b3a 100644 (file)
@@ -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===
\ No newline at end of file
+===Done===
index bbb8a2aa57639901978dd71c58aa1b0540abc144..2b6d2f75c868e57ec0b820074edf410cb6937bb2 100644 (file)
@@ -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===
\ No newline at end of file
+===Done===
index 8b6b3cb2ce6e996a462f5e949caa72ffb8a6b3e3..0f7b8a8b6e9392cab1cea83e5a1b0bb810078c26 100644 (file)
@@ -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
index 525956017ef4f23d0ffe1242220569b095972f07..8dc9fb862c66f91333c62069274d7da715cb0dbf 100644 (file)
@@ -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
index dd4725f2441f47ab52b84922a060622fa0a66057..d4b94ec0568473b269909deb4f5eff8f01c86bce 100644 (file)
@@ -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===
\ No newline at end of file
+===Done===
index 501791f9e5df08b7fbaf81438e59abcc5919d53f..5698cde793c6431017da30b755ce6cc6493c4926 100644 (file)
@@ -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===
\ No newline at end of file
+===DONE===
index 373cf806fe6eb0b46acb1a0ea4e0ade2e161652a..e6a6013931f97bd4d3af69024eb6d9092e649942 100644 (file)
@@ -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 --
 
index 01fd44d66cb4def2aed6f3ac0bc055df84e86710..6e01bf03ddd6fce15d83a7e622515db0cd3c43f0 100644 (file)
@@ -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 --
 
index 124d064576c87b08b99497c7120ceee2221aa746..585d79edb3d5ad46c6c1969910863fa687579b48 100644 (file)
@@ -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 --