Skip to content
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

Prevent empty term status from being interpreted as new-rejected during bulk change #1460

Merged
merged 1 commit into from
Sep 24, 2018
Merged
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
7 changes: 7 additions & 0 deletions includes/validation/class-amp-validation-error-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ public static function delete_empty_terms() {
public static function sanitize_term_status( $status, $options = array() ) {
$multiple = ! empty( $options['multiple'] );

// Catch case where an empty string is supplied. Prevent casting to 0.
if ( ! is_numeric( $status ) && empty( $status ) ) {
return $multiple ? array() : null;
}

if ( is_string( $status ) ) {
$statuses = wp_parse_id_list( $status );
} else {
Expand Down Expand Up @@ -940,6 +945,8 @@ public static function add_term_filter_query_var( $url, $tax ) {
array( self::VALIDATION_ERROR_STATUS_QUERY_VAR => $groups ),
$url
);
} else {
$url = remove_query_arg( self::VALIDATION_ERROR_STATUS_QUERY_VAR, $url );
}

return $url;
Expand Down
13 changes: 9 additions & 4 deletions tests/validation/test-class-amp-validation-error-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,16 @@ public function test_delete_empty_terms() {
* @covers \AMP_Validation_Error_Taxonomy::sanitize_term_status()
*/
public function test_sanitize_term_status() {
$this->assertNull( AMP_Validation_Error_Taxonomy::sanitize_term_status( '' ) );
$this->assertNull( AMP_Validation_Error_Taxonomy::sanitize_term_status( false ) );
$this->assertNull( AMP_Validation_Error_Taxonomy::sanitize_term_status( null ) );
$this->assertSame( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, AMP_Validation_Error_Taxonomy::sanitize_term_status( '0' ) );
$this->assertSame( array(), AMP_Validation_Error_Taxonomy::sanitize_term_status( '', array( 'multiple' => true ) ) );
$this->assertNull( AMP_Validation_Error_Taxonomy::sanitize_term_status( '100' ) );
$this->assertEquals( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, AMP_Validation_Error_Taxonomy::sanitize_term_status( (string) AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS ) );
$this->assertEquals( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS, AMP_Validation_Error_Taxonomy::sanitize_term_status( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS ) );
$this->assertEquals( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS, AMP_Validation_Error_Taxonomy::sanitize_term_status( (string) AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS ) );
$this->assertEquals( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, AMP_Validation_Error_Taxonomy::sanitize_term_status( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, array( 'multiple' => false ) ) );
$this->assertSame( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, AMP_Validation_Error_Taxonomy::sanitize_term_status( (string) AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS ) );
$this->assertSame( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS, AMP_Validation_Error_Taxonomy::sanitize_term_status( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS ) );
$this->assertSame( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS, AMP_Validation_Error_Taxonomy::sanitize_term_status( (string) AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS ) );
$this->assertSame( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, AMP_Validation_Error_Taxonomy::sanitize_term_status( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, array( 'multiple' => false ) ) );

$this->assertEquals(
array(
Expand Down