- Timestamp:
- 11/08/2017 11:47:04 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/random_compat/byte_safe_strings.php
r36886 r42130 6 6 * The MIT License (MIT) 7 7 * 8 * Copyright (c) 2015 Paragon Initiative Enterprises8 * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises 9 9 * 10 10 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 27 27 */ 28 28 29 if (! function_exists('RandomCompat_strlen')) {29 if (!is_callable('RandomCompat_strlen')) { 30 30 if ( 31 31 defined('MB_OVERLOAD_STRING') && … … 52 52 } 53 53 54 return mb_strlen($binary_string, '8bit');54 return (int) mb_strlen($binary_string, '8bit'); 55 55 } 56 56 … … 74 74 ); 75 75 } 76 return strlen($binary_string);76 return (int) strlen($binary_string); 77 77 } 78 78 } 79 79 } 80 80 81 if (! function_exists('RandomCompat_substr')) {81 if (!is_callable('RandomCompat_substr')) { 82 82 83 83 if ( … … 119 119 * PHP 5.3, so we have to find the length ourselves. 120 120 */ 121 $length = RandomCompat_strlen($ length) - $start;121 $length = RandomCompat_strlen($binary_string) - $start; 122 122 } elseif (!is_int($length)) { 123 123 throw new TypeError( … … 126 126 } 127 127 128 return mb_substr($binary_string, $start, $length, '8bit'); 128 // Consistency with PHP's behavior 129 if ($start === RandomCompat_strlen($binary_string) && $length === 0) { 130 return ''; 131 } 132 if ($start > RandomCompat_strlen($binary_string)) { 133 return ''; 134 } 135 136 return (string) mb_substr($binary_string, $start, $length, '8bit'); 129 137 } 130 138 … … 165 173 } 166 174 167 return substr($binary_string, $start, $length);175 return (string) substr($binary_string, $start, $length); 168 176 } 169 177 170 return substr($binary_string, $start);178 return (string) substr($binary_string, $start); 171 179 } 172 180 }
Note: See TracChangeset
for help on using the changeset viewer.