Make WordPress Core

Ticket #43977: 43977.diff

File 43977.diff, 5.4 KB (added by sstoqnov, 7 years ago)

Add PREG_SPLIT_NO_EMPTY flag to preg_split to avoid arrays with empty values

  • src/wp-includes/bookmark.php

     
    171171                $r['exclude']       = '';  //ignore exclude, category, and category_name params if using include
    172172                $r['category']      = '';
    173173                $r['category_name'] = '';
    174                 $inclinks           = preg_split( '/[\s,]+/', $r['include'] );
     174                $inclinks           = preg_split( '/[\s,]+/', $r['include'], -1, PREG_SPLIT_NO_EMPTY );
    175175                if ( count( $inclinks ) ) {
    176176                        foreach ( $inclinks as $inclink ) {
    177177                                if ( empty( $inclusions ) ) {
     
    188188
    189189        $exclusions = '';
    190190        if ( ! empty( $r['exclude'] ) ) {
    191                 $exlinks = preg_split( '/[\s,]+/', $r['exclude'] );
     191                $exlinks = preg_split( '/[\s,]+/', $r['exclude'], -1, PREG_SPLIT_NO_EMPTY );
    192192                if ( count( $exlinks ) ) {
    193193                        foreach ( $exlinks as $exlink ) {
    194194                                if ( empty( $exclusions ) ) {
     
    223223        $category_query = '';
    224224        $join           = '';
    225225        if ( ! empty( $r['category'] ) ) {
    226                 $incategories = preg_split( '/[\s,]+/', $r['category'] );
     226                $incategories = preg_split( '/[\s,]+/', $r['category'], -1, PREG_SPLIT_NO_EMPTY );
    227227                if ( count( $incategories ) ) {
    228228                        foreach ( $incategories as $incat ) {
    229229                                if ( empty( $category_query ) ) {
  • src/wp-includes/class-wp-comment-query.php

     
    484484                $status_clauses = array();
    485485                $statuses       = $this->query_vars['status'];
    486486                if ( ! is_array( $statuses ) ) {
    487                         $statuses = preg_split( '/[\s,]+/', $statuses );
     487                        $statuses = preg_split( '/[\s,]+/', $statuses, -1, PREG_SPLIT_NO_EMPTY );
    488488                }
    489489
    490490                // 'any' overrides other statuses.
     
    521521
    522522                        // Accepts arrays or comma-separated strings.
    523523                        if ( ! is_array( $include_unapproved ) ) {
    524                                 $include_unapproved = preg_split( '/[\s,]+/', $include_unapproved );
     524                                $include_unapproved = preg_split( '/[\s,]+/', $include_unapproved, -1, PREG_SPLIT_NO_EMPTY );
    525525                        }
    526526
    527527                        $unapproved_ids = $unapproved_emails = array();
  • src/wp-includes/functions.php

     
    36933693 */
    36943694function wp_parse_id_list( $list ) {
    36953695        if ( ! is_array( $list ) ) {
    3696                 $list = preg_split( '/[\s,]+/', $list );
     3696                $list = preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
    36973697        }
    36983698
    36993699        return array_unique( array_map( 'absint', $list ) );
     
    37093709 */
    37103710function wp_parse_slug_list( $list ) {
    37113711        if ( ! is_array( $list ) ) {
    3712                 $list = preg_split( '/[\s,]+/', $list );
     3712                $list = preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
    37133713        }
    37143714
    37153715        foreach ( $list as $key => $value ) {
  • src/wp-includes/post.php

     
    49654965
    49664966        $author_query = '';
    49674967        if ( ! empty( $r['authors'] ) ) {
    4968                 $post_authors = preg_split( '/[\s,]+/', $r['authors'] );
     4968                $post_authors = preg_split( '/[\s,]+/', $r['authors'], -1, PREG_SPLIT_NO_EMPTY );
    49694969
    49704970                if ( ! empty( $post_authors ) ) {
    49714971                        foreach ( $post_authors as $post_author ) {
  • src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php

     
    521521                if ( ! isset( $request['_fields'] ) ) {
    522522                        return $fields;
    523523                }
    524                 $requested_fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'] );
     524                $requested_fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'], -1, PREG_SPLIT_NO_EMPTY );
    525525                if ( 0 === count( $requested_fields ) ) {
    526526                        return $fields;
    527527                }
  • src/wp-includes/rest-api.php

     
    651651
    652652        $data = $response->get_data();
    653653
    654         $fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'] );
     654        $fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'], -1, PREG_SPLIT_NO_EMPTY );
    655655
    656656        if ( 0 === count( $fields ) ) {
    657657                return $response;
     
    10821082function rest_validate_value_from_schema( $value, $args, $param = '' ) {
    10831083        if ( 'array' === $args['type'] ) {
    10841084                if ( ! is_array( $value ) ) {
    1085                         $value = preg_split( '/[\s,]+/', $value );
     1085                        $value = preg_split( '/[\s,]+/', $value, -1, PREG_SPLIT_NO_EMPTY );
    10861086                }
    10871087                if ( ! wp_is_numeric_array( $value ) ) {
    10881088                        /* translators: 1: parameter, 2: type name */
     
    12261226                        return (array) $value;
    12271227                }
    12281228                if ( ! is_array( $value ) ) {
    1229                         $value = preg_split( '/[\s,]+/', $value );
     1229                        $value = preg_split( '/[\s,]+/', $value, -1, PREG_SPLIT_NO_EMPTY );
    12301230                }
    12311231                foreach ( $value as $index => $v ) {
    12321232                        $value[ $index ] = rest_sanitize_value_from_schema( $v, $args['items'] );