@@ -52,6 +52,55 @@ public function test_allow_comment_if_comment_author_emails_differ() {
5252 $ this ->assertSame ( 1 , $ result );
5353 }
5454
55+ /**
56+ * @ticket 40319
57+ * @covers ::check_comment
58+ */
59+ public function test_allow_comment_if_previously_approved_author_name_and_email_contain_apostrophe () {
60+ update_option ( 'comment_previously_approved ' , 1 );
61+ add_filter ( 'comment_flood_filter ' , '__return_false ' );
62+
63+ $ now = time ();
64+
65+ // Insert an already-approved comment with apostrophe in name and email.
66+ $ approved_comment_id = wp_insert_comment (
67+ array (
68+ 'comment_post_ID ' => self ::$ post_id ,
69+ 'comment_approved ' => '1 ' ,
70+ 'comment_author ' => "O'Brien " ,
71+ 'comment_author_email ' => "o'brien@example.com " ,
72+ 'comment_author_url ' => 'http://example.com ' ,
73+ 'comment_content ' => 'Test comment. ' ,
74+ 'comment_parent ' => 0 ,
75+ 'comment_author_IP ' => '192.168.0.1 ' ,
76+ 'comment_date_gmt ' => gmdate ( 'Y-m-d H:i:s ' , $ now - 60 ),
77+ 'comment_agent ' => 'TestAgent/1.0 ' ,
78+ 'comment_type ' => '' ,
79+ )
80+ );
81+
82+ $ new_comment = array (
83+ 'comment_post_ID ' => self ::$ post_id ,
84+ 'comment_author ' => wp_slash ( "O'Brien " ),
85+ 'comment_author_email ' => wp_slash ( "o'brien@example.com " ),
86+ 'comment_author_url ' => 'http://example.com ' ,
87+ 'comment_content ' => 'A new comment. ' ,
88+ 'comment_parent ' => 0 ,
89+ 'comment_author_IP ' => '192.168.0.1 ' ,
90+ 'comment_date_gmt ' => gmdate ( 'Y-m-d H:i:s ' , $ now ),
91+ 'comment_agent ' => 'TestAgent/1.0 ' ,
92+ 'comment_type ' => '' ,
93+ );
94+
95+ $ result = wp_allow_comment ( $ new_comment );
96+
97+ wp_delete_comment ( $ approved_comment_id , true );
98+ update_option ( 'comment_previously_approved ' , 0 );
99+ remove_filter ( 'comment_flood_filter ' , '__return_false ' );
100+
101+ $ this ->assertSame ( 1 , $ result , 'Comment from previously-approved author with apostrophe in name/email should be auto-approved. ' );
102+ }
103+
55104 public function test_die_as_duplicate_if_comment_author_name_and_emails_match () {
56105 $ this ->expectException ( 'WPDieException ' );
57106
0 commit comments