Make WordPress Core

Changeset 39717


Ignore:
Timestamp:
01/05/2017 04:20:40 PM (10 years ago)
Author:
joemcgill
Message:

Media: Improved media titles when created from filename.

Preserves spaces and generally creates more accurate, cleaner titles from filenames of uploaded media.

Merge of [38615] to the 3.9 branch.

Fixes #37989.

Location:
branches/3.9
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.9

  • branches/3.9/src/wp-admin/includes/media.php

    r38546 r39717  
    263263        $type = $file['type'];
    264264        $file = $file['file'];
    265         $title = sanitize_title( $name );
     265        $title = sanitize_text_field( $name );
    266266        $content = '';
    267267
  • branches/3.9/tests/phpunit/tests/media.php

    r33523 r39717  
    439439
    440440        /**
     441         * @ticket 37989
     442         */
     443        public function test_media_handle_upload_expected_titles() {
     444                $test_file = DIR_TESTDATA . '/images/test-image.jpg';
     445
     446                // Make a copy of this file as it gets moved during the file upload
     447                $tmp_name = wp_tempnam( $test_file );
     448
     449                copy( $test_file, $tmp_name );
     450
     451                $_FILES['upload'] = array(
     452                        'tmp_name' => $tmp_name,
     453                        'name'     => 'This is a test.jpg',
     454                        'type'     => 'image/jpeg',
     455                        'error'    => 0,
     456                        'size'     => filesize( $test_file ),
     457                );
     458
     459                $post_id = media_handle_upload( 'upload', 0, array(), array( 'action' => 'test_upload_titles', 'test_form' => false ) );
     460
     461                unset( $_FILES['upload'] );
     462
     463                $post = get_post( $post_id );
     464
     465                // Clean up.
     466                wp_delete_attachment( $post_id );
     467
     468                $this->assertEquals( 'This is a test', $post->post_title );
     469        }
     470
     471        /**
    441472         * @ticket 33016
    442473         */
Note: See TracChangeset for help on using the changeset viewer.