-
Notifications
You must be signed in to change notification settings - Fork 10
Description
I discovered this while working on #13. I believe I confirmed it's not a regression, but would welcome confirmation.
Issue
When re-flagging a comment, I do not get the expected "already flagged" message.
Reproduce
- Activate the plugin on a site running any default theme but Twenty Twenty (See if there are better options than comment_reply_link #14).
- Add an approve at least one comment for testing on.
- View the comment on the front-end and click "Report Comment"
- Note you'll get a
sfrc_flags
cookie value something like thiseyIxOTAzMCI6MX0%3D
The problem is during unserialization
safe-report-comments/safe-report-comments.php
Lines 248 to 251 in d28439f
private function unserialize_cookie( $value ) { | |
$data = json_decode( base64_decode( $value ) ); | |
return $this->clean_cookie_data( $data ); | |
} |
Problem one is the base64 decoding leaves a trailing character
wp> $base64 = base64_decode( 'eyIxOTAzMCI6MX0%3D' )
=> string(12) "{"19030":1}7"
Which then prevents json decoding
wp> json_decode( $base64 );
=> NULL
Because the data ends up as null (which is "cleaned" into an empty array), our comment isn't found in the data so is not considered "already flagged".
Note: It may be difficult to fully see this on the front-end due to the transients fallback. Conditional blocks at
safe-report-comments/safe-report-comments.php
Line 298 in d28439f
if ( $transient = get_transient( md5( $this->_storagecookie . $remote_addr ) ) ) { |
safe-report-comments/safe-report-comments.php
Line 346 in d28439f
if ( !$transient ) { |