[wp-trac] [WordPress Trac] #50098: CSVs that contain HTML fail upload test

WordPress Trac noreply at wordpress.org
Wed May 6 06:42:45 UTC 2020


#50098: CSVs that contain HTML fail upload test
--------------------------+-----------------------------
 Reporter:  JakePT        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Upload        |    Version:
 Severity:  normal        |   Keywords:  needs-patch
  Focuses:                |
--------------------------+-----------------------------
 WordPress 5.0.1 (I believe) introduced file type checking so that uploaded
 files needed to be the correct MIME type for its extension. This caused
 CSVs detected as `text/plain` to fail the upload test. WordPress 5.0.3
 fixed this so that .csv files can be uploaded if detected as `text/plain`
 (#45615, [44443]).

 However, in trying to uploaded CSVs exported from WooCommerce, I have
 encountered CSVs that are detected as `text/html` if they have enough HTML
 in the product descriptions. So these files exported from WooCommerce
 cannot be re-uploaded to WooCommerce.

 I have worked around the issue using the `wp_check_filetype_and_ext`
 filter, but ideally a similar carve-out for `text/plain` would be made for
 `text/html`.

 I don't have time to write a patch right now, but I might be able to take
 a crack at it later this week/next week if no one else can.

 For reference, this is how I bypassed the issue with the filter:

 {{{
 add_filter(
         'wp_check_filetype_and_ext',
         function( $wp_check_filetype_and_ext, $file, $filename, $mimes,
 $real_mime ) {
                 $wp_filetype = wp_check_filetype( $filename );

                 if ( 'text/html' === $real_mime && 'text/csv' ===
 $wp_filetype['type'] ) {
                         $wp_check_filetype_and_ext = [
                                 'ext'              => $wp_filetype['ext'],
                                 'type'             =>
 $wp_filetype['type'],
                                 'proper_filename'  => $filename,
                         ];
                 }

                 return $wp_check_filetype_and_ext;
         },
         10,
         5,
 );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50098>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list