Make WordPress Core

Ticket #36170: 36170.2.diff

File 36170.2.diff, 1.5 KB (added by borgesbruno, 10 years ago)

Using type hint and changing the provider

  • src/wp-includes/functions.php

     
    40004000 * @param array  $allowed_files List of allowed files.
    40014001 * @return int 0 means nothing is wrong, greater than 0 means something was wrong.
    40024002 */
    4003 function validate_file( $file, $allowed_files = '' ) {
     4003function validate_file( $file, array $allowed_files = array()    ) {
    40044004        if ( false !== strpos( $file, '..' ) )
    40054005                return 1;
    40064006
  • tests/phpunit/tests/functions.php

     
    150150                );
    151151        }
    152152
     153        /**
     154         * @dataProvider file_path_provider
     155         */
     156        function test_validate_file($result, $allowed_files, $expected)
     157        {
     158                $this->assertEquals(validate_file('../foo/foo.txt'), 1);
     159                $this->assertEquals($expected, validate_file($result, $allowed_files));
     160        }
     161
     162        function file_path_provider() {
     163                return array(
     164                        array('../foo/foo.txt', array(), 1),
     165                        array('../foo.txt', array(), 1),
     166                        array('../foo.bar', array(), 1),
     167                        array('foo/bar/foo.txt', array(), 0),
     168                        array('FOO/foo.txt', array(), 0),
     169                        array('C:/WINDOWS/system32', array(), 2),
     170                        array('./FOO/foo.txt', array(), 1),
     171                        array('/FOO/notallowed.txt', array('/FOO/allowed.txt'), 3)
     172                );
     173        }
     174
    153175        function test_wp_unique_filename() {
    154176
    155177                $testdir = DIR_TESTDATA . '/images/';