WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/08/2017 11:47:04 AM (4 years ago)
Author:
dd32
Message:

External Libraries: Update Random_Compat from 1.2.1 to 2.0.11.

Notably this fixes PHP7 parse errors of the files and removes the OpenSSL functionality.
Full Changes: https://github.com/paragonie/random_compat/compare/v1.2.1...v2.0.11

Props jrdelarosa.
See #42439.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/random_compat/byte_safe_strings.php

    r36886 r42130  
    66 * The MIT License (MIT)
    77 *
    8  * Copyright (c) 2015 Paragon Initiative Enterprises
     8 * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises
    99 *
    1010 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    2727 */
    2828
    29 if (!function_exists('RandomCompat_strlen')) {
     29if (!is_callable('RandomCompat_strlen')) {
    3030    if (
    3131        defined('MB_OVERLOAD_STRING') &&
     
    5252            }
    5353
    54             return mb_strlen($binary_string, '8bit');
     54            return (int) mb_strlen($binary_string, '8bit');
    5555        }
    5656
     
    7474                );
    7575            }
    76             return strlen($binary_string);
     76            return (int) strlen($binary_string);
    7777        }
    7878    }
    7979}
    8080
    81 if (!function_exists('RandomCompat_substr')) {
     81if (!is_callable('RandomCompat_substr')) {
    8282
    8383    if (
     
    119119                 * PHP 5.3, so we have to find the length ourselves.
    120120                 */
    121                 $length = RandomCompat_strlen($length) - $start;
     121                $length = RandomCompat_strlen($binary_string) - $start;
    122122            } elseif (!is_int($length)) {
    123123                throw new TypeError(
     
    126126            }
    127127
    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');
    129137        }
    130138
     
    165173                }
    166174
    167                 return substr($binary_string, $start, $length);
     175                return (string) substr($binary_string, $start, $length);
    168176            }
    169177
    170             return substr($binary_string, $start);
     178            return (string) substr($binary_string, $start);
    171179        }
    172180    }
Note: See TracChangeset for help on using the changeset viewer.