Make WordPress Core


Ignore:
Timestamp:
07/06/2017 07:04:11 AM (7 years ago)
Author:
westonruter
Message:

Customize: Prevent edge case fatal error when attempting to save changes to a changeset that had previously been corrupted.

Check return value of WP_Customize_Manager::get_changeset_post_data() and return if error instead of assuming it is an array.

Amends [38810].
See #30937.
Fixes #41252.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/manager.php

    r40521 r41012  
    12931293
    12941294    /**
     1295     * Ensure that save_changeset_post method bails updating an underlying changeset which is invalid.
     1296     *
     1297     * @ticket 41252
     1298     * @covers WP_Customize_Manager::save_changeset_post
     1299     * @covers WP_Customize_Manager::get_changeset_post_data
     1300     */
     1301    function test_save_changeset_post_for_bad_changeset() {
     1302        $uuid = wp_generate_uuid4();
     1303        $post_id = wp_insert_post( array(
     1304            'post_type' => 'customize_changeset',
     1305            'post_content' => 'INVALID_JSON',
     1306            'post_name' => $uuid,
     1307            'post_status' => 'auto-draft',
     1308            'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '-3 days' ) ),
     1309        ) );
     1310        $manager = $this->create_test_manager( $uuid );
     1311        $args = array(
     1312            'data' => array(
     1313                'blogname' => array(
     1314                    'value' => 'Test',
     1315                ),
     1316            ),
     1317        );
     1318
     1319        $r = $manager->save_changeset_post( $args );
     1320        $this->assertInstanceOf( 'WP_Error', $r );
     1321        if ( function_exists( 'json_last_error' ) ) {
     1322            $this->assertEquals( 'json_parse_error', $r->get_error_code() );
     1323        }
     1324
     1325        wp_update_post( array(
     1326            'ID' => $post_id,
     1327            'post_content' => 'null',
     1328        ) );
     1329        $r = $manager->save_changeset_post( $args );
     1330        $this->assertInstanceOf( 'WP_Error', $r );
     1331        $this->assertEquals( 'expected_array', $r->get_error_code() );
     1332    }
     1333
     1334    /**
    12951335     * Register scratchpad setting.
    12961336     *
Note: See TracChangeset for help on using the changeset viewer.