Make WordPress Core


Ignore:
Timestamp:
10/09/2019 05:34:20 PM (6 years ago)
Author:
kadamwhite
Message:

REST API: Do not addslash when receiving meta arrays of non-string values.

Slashing non-string data caused PUT requests containing unmodified meta arrays of integers to fail the check against the existing stored meta value, causing a 500 when posting an unmodified response body back to the server.

Props TimothyBlynJacobs, augustuswm.
Fixes #48264.

File:
1 edited

Legend:

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

    r46451 r46454  
    54085408
    54095409/**
     5410 * Adds slashes to only string values in an array of values.
     5411 *
     5412 * This should be used when preparing data for core APIs that expect slashed data.
     5413 * This should not be used to escape data going directly into an SQL query.
     5414 *
     5415 * @since 5.3.0
     5416 *
     5417 * @param mixed $value Scalar or array of scalars.
     5418 * @return mixed Slashes $value
     5419 */
     5420function wp_slash_strings_only( $value ) {
     5421    return map_deep( $value, 'addslashes_strings_only' );
     5422}
     5423
     5424/**
     5425 * Adds slashes only if the provided value is a string.
     5426 *
     5427 * @since 5.3.0
     5428 *
     5429 * @param mixed $value
     5430 * @return mixed
     5431 */
     5432function addslashes_strings_only( $value ) {
     5433    return is_string( $value ) ? addslashes( $value ) : $value;
     5434}
     5435
     5436/**
    54105437 * Extract and return the first URL from passed content.
    54115438 *
Note: See TracChangeset for help on using the changeset viewer.