Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Ensure proper flags are used with `json_encode()`.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function ( $body ) {
)->willReturn(
array(
'response' => array( 'code' => 200 ),
'body' => json_encode( array( 'email_send_success' => true ) ),
'body' => json_encode( array( 'email_send_success' => true ), JSON_UNESCAPED_SLASHES ),
)
);

Expand Down Expand Up @@ -197,7 +197,8 @@ public function test_api_send_auth_email_returns_error_if_response_code_is_not_2
'code' => 'email_send_error',
'message' => 'Failed to send authentication code.',
'email_send_success' => true,
)
),
JSON_UNESCAPED_SLASHES
),
)
);
Expand Down Expand Up @@ -252,7 +253,7 @@ public function test_api_send_auth_email_returns_error_if_response_from_api_is_f
->willReturn(
array(
'response' => array( 'code' => 200 ),
'body' => json_encode( array( 'email_sent' => false ) ),
'body' => json_encode( array( 'email_sent' => false ), JSON_UNESCAPED_SLASHES ),
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ public function test_returns_true_if_password_is_compromised() {
'body' => json_encode(
array(
'compromised' => array( 'c90fcfd699f0ddbdcb30c2c9183d2d933ea' ),
)
),
JSON_UNESCAPED_SLASHES
),
)
);
Expand All @@ -261,7 +262,8 @@ public function test_returns_true_if_password_is_common() {
'body' => json_encode(
array(
'common' => array( 'c90fcfd699f0ddbdcb30c2c9183d2d933ea' ),
)
),
JSON_UNESCAPED_SLASHES
),
)
);
Expand All @@ -286,7 +288,8 @@ public function test_returns_false_if_password_is_not_leaked() {
array(
'compromised' => array( '1234' ),
'common' => array(),
)
),
JSON_UNESCAPED_SLASHES
),
)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Ensure proper flags are used with `json_encode()`.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function to_csv_array() {
$this->class_name,
$this->method_name,
$this->static,
json_encode( $this->params ),
json_encode( $this->params, JSON_UNESCAPED_SLASHES ),
$this->deprecated,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function to_csv_array() {
'',
$this->func_name,
'',
json_encode( $this->params ),
json_encode( $this->params, JSON_UNESCAPED_SLASHES ),
$this->deprecated,
);
}
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/analyzer/src/api/class-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function persist( $arr = null ) {
if ( $arr === null ) {
$arr = $this->content;
}
file_put_contents( $this->db_file, json_encode( $arr ) );
file_put_contents( $this->db_file, json_encode( $arr ), JSON_UNESCAPED_SLASHES );
}

public function reset() {
Expand Down
3 changes: 2 additions & 1 deletion projects/packages/analyzer/src/class-PersistentList.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ function ( $item ) {
return $item->to_map();
},
$this->items
)
),
JSON_UNESCAPED_SLASHES
)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Ensure proper flags are used with `json_encode()`.
2 changes: 1 addition & 1 deletion projects/packages/assets/src/class-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ public static function wp_default_scripts_hook( $wp_scripts ) {
} else {
$data['domainMap'] = (object) $data['domainMap']; // Ensure it becomes a json object.
$data['domainPaths'] = (object) $data['domainPaths']; // Ensure it becomes a json object.
$wp_scripts->add_inline_script( $handle, 'wp.jpI18nLoader.state = ' . wp_json_encode( $data, JSON_UNESCAPED_SLASHES ) . ';' );
$wp_scripts->add_inline_script( $handle, 'wp.jpI18nLoader.state = ' . wp_json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ';' );
}

// Deprecated state module: Depend on wp-i18n to ensure global `wp` exists and because anything needing this will need that too.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Ensure proper flags are used with `json_encode()`.
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ private function has_plugin_changed( $plugin_dir, $plugin_file, &$composer_confi
// Prepare a checksum object for comparison and store it in the composer config so we can retrieve it later.
$factory_checksum = array(
'plugin' => hash( 'crc32', $plugin_file ),
'composer' => hash( 'crc32', json_encode( $composer_config ) ),
'composer' => hash( 'crc32', json_encode( $composer_config, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ),
'files' => array(),
);
foreach ( $this->files as $path => $content ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Ensure proper flags are used with `json_encode()`.
2 changes: 1 addition & 1 deletion projects/packages/backup/src/class-initial-state.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ private function get_data() {
public function render() {
add_action( 'jetpack_use_iframe_authorization_flow', '__return_true' );

return 'var JPBACKUP_INITIAL_STATE=JSON.parse(decodeURIComponent("' . rawurlencode( wp_json_encode( $this->get_data() ) ) . '"));';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message should mention that we took the opportunity to clean up this sort of PHP 5.2 compatibility code (the various flags weren't introduced until 5.3).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

return 'var JPBACKUP_INITIAL_STATE=' . wp_json_encode( $this->get_data(), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ';';
}
}
12 changes: 6 additions & 6 deletions projects/packages/backup/tests/php/REST_Controller_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function test_install_backup_helper_script_unauthorized() {
);
$request = new WP_REST_Request( 'POST', '/jetpack/v4/backup-helper-script' );
$request->set_header( 'content-type', 'application/json' );
$request->set_body( wp_json_encode( $body ) );
$request->set_body( wp_json_encode( $body, JSON_UNESCAPED_SLASHES ) );
$response = $this->server->dispatch( $request );
$this->assertEquals( 403, $response->get_status() );
$this->assertEquals( 'You are not allowed to perform this action.', $response->get_data()['message'] );
Expand All @@ -128,7 +128,7 @@ public function test_install_backup_helper_script_success() {

$request = new WP_REST_Request( 'POST', '/jetpack/v4/backup-helper-script' );
$request->set_header( 'content-type', 'application/json' );
$request->set_body( wp_json_encode( $body ) );
$request->set_body( wp_json_encode( $body, JSON_UNESCAPED_SLASHES ) );

$response = $this->dispatch_request_signed_with_blog_token( $request );
$response_data = $response->get_data();
Expand Down Expand Up @@ -167,7 +167,7 @@ public function test_install_backup_helper_script_bad_header() {

$request = new WP_REST_Request( 'POST', '/jetpack/v4/backup-helper-script' );
$request->set_header( 'content-type', 'application/json' );
$request->set_body( wp_json_encode( $body ) );
$request->set_body( wp_json_encode( $body, JSON_UNESCAPED_SLASHES ) );

$response = $this->dispatch_request_signed_with_blog_token( $request );
$this->assertEquals( 400, $response->get_status() );
Expand Down Expand Up @@ -196,7 +196,7 @@ public function test_delete_backup_helper_script_unauthorized() {

$request = new WP_REST_Request( 'DELETE', '/jetpack/v4/backup-helper-script' );
$request->set_header( 'content-type', 'application/json' );
$request->set_body( wp_json_encode( $body ) );
$request->set_body( wp_json_encode( $body, JSON_UNESCAPED_SLASHES ) );
$response = $this->server->dispatch( $request );

$this->assertEquals( 403, $response->get_status() );
Expand All @@ -213,7 +213,7 @@ public function test_delete_backup_helper_script_success() {

$request = new WP_REST_Request( 'DELETE', '/jetpack/v4/backup-helper-script' );
$request->set_header( 'content-type', 'application/json' );
$request->set_body( wp_json_encode( $body ) );
$request->set_body( wp_json_encode( $body, JSON_UNESCAPED_SLASHES ) );

$response = $this->dispatch_request_signed_with_blog_token( $request );
$this->assertEquals( 200, $response->get_status() );
Expand All @@ -232,7 +232,7 @@ public function test_delete_backup_helper_script_bad_header() {

$request = new WP_REST_Request( 'DELETE', '/jetpack/v4/backup-helper-script' );
$request->set_header( 'content-type', 'application/json' );
$request->set_body( wp_json_encode( $body ) );
$request->set_body( wp_json_encode( $body, JSON_UNESCAPED_SLASHES ) );

$response = $this->dispatch_request_signed_with_blog_token( $request );
$this->assertEquals( 500, $response->get_status() );
Expand Down
4 changes: 4 additions & 0 deletions projects/packages/blaze/changelog/fix-audit_json_encode_flags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Ensure proper flags are used with `json_encode()`.
3 changes: 2 additions & 1 deletion projects/packages/blaze/src/class-dashboard-config-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function __construct( $admin_page = 'tools.php', $menu_slug = 'advertisin
*/
public function get_js_config_data( $config_data = null ) {
return 'window.configData = ' . wp_json_encode(
$config_data === null ? $this->get_data() : $config_data
$config_data === null ? $this->get_data() : $config_data,
JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP
) . ';';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ protected function add_prices_in_posts( $posts ) {
*/
protected function request_as_user( $path, $version = '2', $args = array(), $body = null, $base_api_path = 'wpcom', $use_cache = false ) {
// Arrays are serialized without considering the order of objects, but it's okay atm.
$cache_key = 'BLAZE_REST_RESP_' . md5( implode( '|', array( $path, $version, wp_json_encode( $args ), wp_json_encode( $body ), $base_api_path ) ) );
$cache_key = 'BLAZE_REST_RESP_' . md5( implode( '|', array( $path, $version, wp_json_encode( $args, JSON_UNESCAPED_SLASHES ), wp_json_encode( $body, JSON_UNESCAPED_SLASHES ), $base_api_path ) ) );

if ( $use_cache ) {
$response_body_content = get_transient( $cache_key );
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/blaze/tests/php/Blaze_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function test_site_supports_blaze( $eligibility_details, $expected_eligib
set_transient( 'jetpack_blaze_site_supports_blaze_0', $eligibility_details['transient'] );
} else {
if ( isset( $eligibility_details['body'] ) ) {
$eligibility_details['body'] = wp_json_encode( $eligibility_details['body'] );
$eligibility_details['body'] = wp_json_encode( $eligibility_details['body'], JSON_UNESCAPED_SLASHES );
}

$remote_request_happened = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Ensure proper flags are used with `json_encode()`.
4 changes: 2 additions & 2 deletions projects/packages/boost-core/src/lib/class-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function standardize_error( $error ) {
if ( is_object( $error ) ) {
return array(
'name' => 'Error',
'message' => json_decode( wp_json_encode( $error ), true ),
'message' => json_decode( wp_json_encode( $error, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ), true ),
);
}

Expand Down Expand Up @@ -114,7 +114,7 @@ public static function send_wpcom_request( $method, $endpoint, $args = null, $bo
$endpoint,
'2',
array_merge( $default_args, empty( $args ) ? array() : $args ),
empty( $body ) ? null : wp_json_encode( $body ),
empty( $body ) ? null : wp_json_encode( $body, JSON_UNESCAPED_SLASHES ),
'wpcom'
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Ensure proper flags are used with `json_encode()`.
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public function testJson( $json, $change ) {
$this->expectExceptionMessage( $change );
ChangeEntry::jsonUnserialize( json_decode( $json ) );
} else {
$this->assertSame( $json, json_encode( $change ) );
$this->assertSame( $json, json_encode( $change, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) );
$this->assertEquals( $change, ChangeEntry::jsonUnserialize( json_decode( $json ) ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public function testJson( $json, $entry ) {
$this->expectExceptionMessage( $entry );
ChangelogEntry::jsonUnserialize( json_decode( $json ) );
} else {
$this->assertSame( $json, json_encode( $entry ) );
$this->assertSame( $json, json_encode( $entry, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) );
$this->assertEquals( $entry, ChangelogEntry::jsonUnserialize( json_decode( $json ) ) );
}
}
Expand All @@ -249,7 +249,7 @@ public static function provideJson() {
( new ChangelogEntry( '1.0' ) )->setTimestamp( '2021-02-18' ),
),
'Serialization with data' => array(
'{"__class__":"Automattic\\\\Jetpack\\\\Changelog\\\\ChangelogEntry","version":"1.0","link":"https:\\/\\/example.org","timestamp":"2021-02-18T12:07:16-0500","prologue":"Foo","epilogue":"Bar","changes":[{"__class__":"Automattic\\\\Jetpack\\\\Changelog\\\\ChangeEntry","significance":null,"timestamp":"2021-02-17T00:00:00+0000","subheading":"","author":"","content":""},{"__class__":"Automattic\\\\Jetpack\\\\Changelog\\\\ChangeEntry","significance":null,"timestamp":"2021-02-18T00:00:00+0000","subheading":"","author":"","content":""}]}',
'{"__class__":"Automattic\\\\Jetpack\\\\Changelog\\\\ChangelogEntry","version":"1.0","link":"https://example.org","timestamp":"2021-02-18T12:07:16-0500","prologue":"Foo","epilogue":"Bar","changes":[{"__class__":"Automattic\\\\Jetpack\\\\Changelog\\\\ChangeEntry","significance":null,"timestamp":"2021-02-17T00:00:00+0000","subheading":"","author":"","content":""},{"__class__":"Automattic\\\\Jetpack\\\\Changelog\\\\ChangeEntry","significance":null,"timestamp":"2021-02-18T00:00:00+0000","subheading":"","author":"","content":""}]}',
( new ChangelogEntry( '1.0' ) )->setTimestamp( '2021-02-18T12:07:16-0500' )->setPrologue( 'Foo' )->setEpilogue( 'Bar' )->setLink( 'https://example.org' )->setChanges(
array(
new ChangeEntry( array( 'timestamp' => '2021-02-17' ) ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function testJson( $json, $changelog ) {
$this->expectExceptionMessage( $changelog );
Changelog::jsonUnserialize( json_decode( $json ) );
} else {
$this->assertSame( $json, json_encode( $changelog ) );
$this->assertSame( $json, json_encode( $changelog, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) );
$this->assertEquals( $changelog, Changelog::jsonUnserialize( json_decode( $json ) ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ function ( $data ) {

$this->assertSame(
'{"a":{"__class__":"Automattic\\\\Jetpack\\\\Changelog\\\\ChangeEntry","significance":"minor","timestamp":"2021-02-22T00:00:00+0000","subheading":"Added!","author":"","content":"AAAAA"},"b":{"__class__":"Automattic\\\\Jetpack\\\\Changelog\\\\ChangeEntry","significance":"minor","timestamp":"2021-02-24T00:00:00+0000","subheading":"Unknown","author":"","content":"BBBBB"}}',
json_encode( $ret )
json_encode( $ret, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE )
);
$this->assertSame(
array(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Ensure proper flags are used with `json_encode()`.
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,15 @@ function jetpack_custom_post_types_loaded() {
if ( ! isset( $_GET['page'] ) || 'jetpack' !== $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We are not processing any data here.
return;
}
$initial_state = 'var CUSTOM_CONTENT_TYPE__INITIAL_STATE; typeof CUSTOM_CONTENT_TYPE__INITIAL_STATE === "object" || (CUSTOM_CONTENT_TYPE__INITIAL_STATE = JSON.parse(decodeURIComponent("' . rawurlencode(
wp_json_encode(
array(
'active' => classic_theme_helper_cpt_should_be_active(),
'over_ride' => false,
'should_show_testimonials' => Jetpack_Testimonial::site_should_display_testimonials() ? true : false,
'should_show_portfolios' => Jetpack_Portfolio::site_should_display_portfolios() ? true : false,
)
)
) . '")));';
$initial_state = 'var CUSTOM_CONTENT_TYPE__INITIAL_STATE; typeof CUSTOM_CONTENT_TYPE__INITIAL_STATE === "object" || (CUSTOM_CONTENT_TYPE__INITIAL_STATE = ' . wp_json_encode(
array(
'active' => classic_theme_helper_cpt_should_be_active(),
'over_ride' => false,
'should_show_testimonials' => Jetpack_Testimonial::site_should_display_testimonials() ? true : false,
'should_show_portfolios' => Jetpack_Portfolio::site_should_display_portfolios() ? true : false,
),
JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP
) . ');';

// Create a global variable with the custom content type feature status so that the value is available
// earlier than the API method above allows, preventing delayed loading of the settings card.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,17 @@ public function process( File $phpcsFile, $stackPtr, array $attributes, array $a
'type' => 'class',
'class' => $d->class,
'alias' => $d->alias,
)
),
JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
);
$ktrait = json_encode(
array(
'which' => $d->which,
'type' => 'trait',
'class' => $d->class,
'alias' => $d->alias,
)
),
JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
);
if ( isset( $attributes[ $kclass ] ) ) {
$annotations[ $kclass ] = $annotations[ $k ];
Expand All @@ -219,7 +221,8 @@ public function process( File $phpcsFile, $stackPtr, array $attributes, array $a
'type' => 'class',
'class' => $d->class,
'alias' => $d->alias,
)
),
JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
);
if ( isset( $attributes[ $kclass ] ) ) {
unset( $attributes[ $k ] );
Expand Down Expand Up @@ -253,13 +256,14 @@ public function process( File $phpcsFile, $stackPtr, array $attributes, array $a
if ( isset( $annotationsByType[ $which ]['function'] ) ) {
foreach ( $annotationsByType[ $which ]['function'] as $k => $d ) {
$k2 = json_encode(
(object) array(
array(
'which' => $d->which,
'type' => 'method',
'class' => $dc->class,
'alias' => $dc->alias,
'method' => $d->function,
)
),
JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
);
$annotations[ $k2 ] = $annotations[ $k ];
unset( $annotations[ $k ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function parseAnnotation( File $phpcsFile, array $data, $applies ) { // p
}
}

return json_encode( $ret );
return json_encode( $ret, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
}

/** {@inheritdoc} */
Expand Down
Loading
Loading