-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sync: silence the call to gzinflate
#34186
Conversation
- Can't always assume that the input is a valid compressed string - There are [no functions](https://www.php.net/manual/en/function.gzinflate.php) that we can use to check if the data is valid - WordPress core also uses `@gzinflate`.
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped. |
@@ -41,7 +41,7 @@ public function encode( $object ) { | |||
* @return array|mixed|object | |||
*/ | |||
public function decode( $input ) { | |||
return $this->json_unserialize( gzinflate( base64_decode( $input ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode | |||
return $this->json_unserialize( @gzinflate( base64_decode( $input ) ) ); // phpcs:ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not use generic phpcs:ignore
. Better to be clear about what exactly we're ignoring.
Also, it seems like it might make more sense to store the result of gzinflate
in a variable and check for false
so we could skip trying to json_unserialize
that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I agree. Addressed these in 436ac0e.
This PR further extends the functionality of a previous PR php#4985. Ran into this while working on a [particular WordPress functionality](Automattic/jetpack#34186) - our servers reported tons of warnings. Currently, the only way to avoid warnings is to call `@gzinflate`, but silencing errors is discouraged so we also have to `phpcs:ignore` it. If `gzinflate` threw an exception instead, it would be much easier for developers to handle this. Applied same reasoning to all the zlib functions. I also found out that the `json` extension also does not use any notices: ``` bor0:~/dev/php-src/ext/json$ grep -R php_error_docref * bor0:~/dev/php-src/ext/json$ ```⚠️ This is a breaking change and may cause code flow interruptions unless handled with exceptions⚠️
This PR further extends the functionality of a previous PR php#4985. Ran into this while working on a [particular WordPress functionality](Automattic/jetpack#34186) - our servers reported tons of warnings. Currently, the only way to avoid warnings is to call `@gzinflate`, but silencing errors is discouraged so we also have to `phpcs:ignore` it. If `gzinflate` threw an exception instead, it would be much easier for developers to handle this. Applied same reasoning to all the zlib functions. I also found out that the `json` extension also does not use any notices: ``` bor0:~/dev/php-src/ext/json$ grep -R php_error_docref * bor0:~/dev/php-src/ext/json$ ```⚠️ This is a breaking change and may cause code flow interruptions unless handled with exceptions⚠️
This PR further extends the functionality of a previous PR php#4985. Ran into this while working on a [particular WordPress functionality](Automattic/jetpack#34186) - our servers reported tons of warnings. Currently, the only way to avoid warnings is to call `@gzinflate`, but silencing errors is discouraged so we also have to `phpcs:ignore` it. If `gzinflate` threw an exception instead, it would be much easier for developers to handle this. Applied same reasoning to all the zlib functions. I also found out that the `json` extension also does not use any notices: ``` bor0:~/dev/php-src/ext/json$ grep -R php_error_docref * bor0:~/dev/php-src/ext/json$ ```⚠️ This is a breaking change and may cause code flow interruptions unless handled with exceptions⚠️
This PR further extends the functionality of a previous PR php#4985. Ran into this while working on a [particular WordPress functionality](Automattic/jetpack#34186) - our servers reported tons of warnings. Currently, the only way to avoid warnings is to call `@gzinflate`, but silencing errors is discouraged so we also have to `phpcs:ignore` it. If `gzinflate` threw an exception instead, it would be much easier for developers to handle this. Applied same reasoning to all the zlib functions. I also found out that the `json` extension also does not use any notices: ``` bor0:~/dev/php-src/ext/json$ grep -R php_error_docref * bor0:~/dev/php-src/ext/json$ ```⚠️ This is a breaking change and may cause code flow interruptions unless handled with exceptions⚠️
gzinflate
gzinflate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Apologies for the late review. Give me a ping to re-approve after resolving conflicts if needed
a857c24
to
bf93f76
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Proposed changes:
Silence the call to
gzinflate
:@gzinflate
.Should fix a few warnings :)
Other information:
Does this pull request change what data or activity we track or use?
No
Testing instructions:
N/A