Make WordPress Core

Changeset 39715


Ignore:
Timestamp:
01/05/2017 04:18:19 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 4.1 branch.

Fixes #37989.

Location:
branches/4.1
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1

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

    r38544 r39715  
    280280        $type = $file['type'];
    281281        $file = $file['file'];
    282         $title = sanitize_title( $name );
     282        $title = sanitize_text_field( $name );
    283283        $content = '';
    284284
  • branches/4.1/tests/phpunit/tests/media.php

    r33521 r39715  
    469469
    470470        /**
     471         * @ticket 37989
     472         */
     473        public function test_media_handle_upload_expected_titles() {
     474                $test_file = DIR_TESTDATA . '/images/test-image.jpg';
     475
     476                // Make a copy of this file as it gets moved during the file upload
     477                $tmp_name = wp_tempnam( $test_file );
     478
     479                copy( $test_file, $tmp_name );
     480
     481                $_FILES['upload'] = array(
     482                        'tmp_name' => $tmp_name,
     483                        'name'     => 'This is a test.jpg',
     484                        'type'     => 'image/jpeg',
     485                        'error'    => 0,
     486                        'size'     => filesize( $test_file ),
     487                );
     488
     489                $post_id = media_handle_upload( 'upload', 0, array(), array( 'action' => 'test_upload_titles', 'test_form' => false ) );
     490
     491                unset( $_FILES['upload'] );
     492
     493                $post = get_post( $post_id );
     494
     495                // Clean up.
     496                wp_delete_attachment( $post_id );
     497
     498                $this->assertEquals( 'This is a test', $post->post_title );
     499        }
     500
     501        /**
    471502         * @ticket 33016
    472503         */
Note: See TracChangeset for help on using the changeset viewer.