Skip to:
Content

BuddyPress.org

Ticket #6884: 6884.02.patch

File 6884.02.patch, 3.0 KB (added by dcavins, 9 years ago)

Break if any of the values in the array are not whitelisted. Adds unit test updates.

  • src/bp-xprofile/classes/class-bp-xprofile-field-type.php

    diff --git src/bp-xprofile/classes/class-bp-xprofile-field-type.php src/bp-xprofile/classes/class-bp-xprofile-field-type.php
    index ccfb2c6..0c8ba43 100644
    abstract class BP_XProfile_Field_Type { 
    206206                        $validated = true;
    207207                }
    208208
    209                 // If there's a whitelist set, also check the $value.
     209                // If there's a whitelist set, make sure that each value is a whitelisted value.
    210210                if ( ( true === $validated ) && ! empty( $values ) && ! empty( $this->validation_whitelist ) ) {
    211211                        foreach ( (array) $values as $value ) {
    212                                 $validated = in_array( $value, $this->validation_whitelist, true );
     212                                if ( ! in_array( $value, $this->validation_whitelist, true ) ) {
     213                                        $validated = false;
     214                                        break;
     215                                }
    213216                        }
    214217                }
    215218
  • tests/phpunit/testcases/xprofile/class-bp-xprofile-field-type.php

    diff --git tests/phpunit/testcases/xprofile/class-bp-xprofile-field-type.php tests/phpunit/testcases/xprofile/class-bp-xprofile-field-type.php
    index 2587d90..6fa2644 100644
    class BP_Tests_XProfile_Field_Type extends BP_UnitTestCase { 
    3838
    3939                $this->assertTrue( $field->is_valid( array( 'cheese', 'pepporoni' ) ) );
    4040                $this->assertTrue( $field->is_valid( array( 'cheese' ) ) );
    41                 $this->assertFalse( $field->is_valid( array( 'cheese', 'pepporoni', 'pinapple' ) ) );
     41                $this->assertFalse( $field->is_valid( array( 'cheese', 'pinapple', 'pepporoni' ) ) );
    4242                $this->assertFalse( $field->is_valid( array( 'pinapple' ) ) );
    4343        }
    4444
    class BP_Tests_XProfile_Field_Type extends BP_UnitTestCase { 
    104104
    105105                $this->assertTrue( $field->is_valid( array( 123 ) ) );
    106106                $this->assertTrue( $field->is_valid( array( 456 ) ) );
    107                 $this->assertFalse( $field->is_valid( array( 123, 456, 789 ) ) );
     107                $this->assertFalse( $field->is_valid( array( 789, 456, 123 ) ) );
    108108                $this->assertFalse( $field->is_valid( array( 789 ) ) );
    109109        }
    110110
    class BP_Tests_XProfile_Field_Type extends BP_UnitTestCase { 
    114114
    115115                $this->assertTrue( $field->is_valid( array( 'cheese', 'pepporoni' ) ) );
    116116                $this->assertTrue( $field->is_valid( array( 'cheese' ) ) );
    117                 $this->assertFalse( $field->is_valid( array( 'cheese', 'pepporoni', 'pinapple' ) ) );
     117                $this->assertFalse( $field->is_valid( array(  'pinapple', 'cheese', 'pepporoni' ) ) );
    118118                $this->assertFalse( $field->is_valid( array( 'pinapple' ) ) );
    119119                $this->assertFalse( $field->is_valid( '' ) );
    120120        }
    class BP_Tests_XProfile_Field_Type extends BP_UnitTestCase { 
    132132
    133133                $this->assertTrue( $field->is_valid( array( 'cheese', 'pepporoni' ) ) );
    134134                $this->assertTrue( $field->is_valid( array( 'cheese' ) ) );
    135                 $this->assertFalse( $field->is_valid( array( 'cheese', 'pepporoni', 'pinapple' ) ) );
     135                $this->assertFalse( $field->is_valid( array( 'pepporoni', 'cheese', 'pinapple' ) ) );
    136136                $this->assertFalse( $field->is_valid( array( 'pinapple' ) ) );
    137137                $this->assertFalse( $field->is_valid( '' ) );
    138138        }