mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Comments: Use a more precise check for disallowed keys on filtered co…
…mment data. The previous approach of running `wp_allow_comment()` twice could have unintended consequences, e.g. the `check_comment_flood` action was also triggered twice, which might lead to false-positive identification of comment flood in case there is some custom callback hooked to it, which is not expecting identical data seeing twice. This commit introduces a new function, `wp_check_comment_data()`, to specifically check for disallowed content before and after comment data is filtered. Follow-up to [59267]. Reviewed by davidbaumwald. Merges [59319] to the 6.7 branch. Props david.binda, SergeyBiryukov. Fixes #61827. git-svn-id: https://develop.svn.wordpress.org/branches/6.7@59322 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
1 parent
42db670
commit 8b4bdea
Showing
2 changed files
with
106 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -989,9 +989,8 @@ public function test_disallowed_keys_match_gives_approved_status_of_trash() { | |
|
||
$comment = wp_handle_comment_submission( $data ); | ||
|
||
$this->assertNotWPError( $comment ); | ||
$this->assertInstanceOf( 'WP_Comment', $comment ); | ||
$this->assertSame( 'trash', $comment->comment_approved ); | ||
$this->assertInstanceOf( 'WP_Comment', $comment, 'The comment was not submitted.' ); | ||
$this->assertSame( 'trash', $comment->comment_approved, 'The wrong approved status was returned.' ); | ||
} | ||
|
||
/** | ||
|
@@ -1009,8 +1008,34 @@ public function test_disallowed_keys_html_match_gives_approved_status_of_trash() | |
|
||
$comment = wp_handle_comment_submission( $data ); | ||
|
||
$this->assertNotWPError( $comment ); | ||
$this->assertInstanceOf( 'WP_Comment', $comment ); | ||
$this->assertSame( 'trash', $comment->comment_approved ); | ||
$this->assertInstanceOf( 'WP_Comment', $comment, 'The comment was not submitted.' ); | ||
$this->assertSame( 'trash', $comment->comment_approved, 'The wrong approved status was returned.' ); | ||
} | ||
|
||
/** | ||
* @ticket 61827 | ||
*/ | ||
public function test_disallowed_keys_filtered_html_match_does_not_call_check_comment_flood_action_twice() { | ||
$data = array( | ||
'comment_post_ID' => self::$post->ID, | ||
'comment' => '<a href=http://example.com/>example</a>', | ||
'author' => 'Comment Author', | ||
'email' => '[email protected]', | ||
); | ||
|
||
update_option( 'disallowed_keys', "href=\\\"http\nfoo" ); | ||
|
||
$pre_comment_approved = new MockAction(); | ||
$check_comment_flood = new MockAction(); | ||
add_filter( 'pre_comment_approved', array( $pre_comment_approved, 'filter' ), 10, 2 ); | ||
add_action( 'check_comment_flood', array( $check_comment_flood, 'action' ), 10, 4 ); | ||
|
||
$comment = wp_handle_comment_submission( $data ); | ||
|
||
$this->assertInstanceOf( 'WP_Comment', $comment, 'The comment was not submitted.' ); | ||
$this->assertSame( 'trash', $comment->comment_approved, 'The wrong approved status was returned.' ); | ||
|
||
$this->assertSame( 2, $pre_comment_approved->get_call_count(), 'The `pre_comment_approved` filter was not called twice.' ); | ||
$this->assertSame( 1, $check_comment_flood->get_call_count(), 'The `check_comment_flood` action was not called exactly once.' ); | ||
} | ||
} |