[wp-trac] [WordPress Trac] #36308: get_attached_file() destroys file paths on Windows

WordPress Trac noreply at wordpress.org
Wed Mar 23 15:45:05 UTC 2016


#36308: get_attached_file() destroys file paths on Windows
--------------------------+-----------------------------
 Reporter:  Whissi        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  4.4.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 While working on ticket #36273 I noticed that ''get_attached_file()'' from
 ''wp-includes/post.php'' will destroy paths normalized by
 ''wp_normalize_path()'' on Windows:

 For example the function starts with
 {{{#!php
 $file = get_post_meta( $attachment_id, '_wp_attached_file', true );
 // $file = 'C:/WWW/Sites/demo/htdocs/wordpress/wp-
 content/uploads/2016/03/example.jpg'
 }}}
 However this will become
 {{{#!php
 $file = 'C:\WWW\Sites\demo\htdocs\wordpress/wp-
 content/uploads/C:/WWW/Sites/demo/htdocs/wordpress/wp-
 content/uploads/2016/03/example.jpg'
 }}}
 due to
 {{{#!php
 if ( $file && 0 !== strpos($file, '/') && !preg_match('|^.:\\\|', $file)
 && ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) )
         $file = $uploads['basedir'] . "/$file";
 }}}

 This is similar to ticket #24824 however we are dealing will full
 qualified paths here, not URLs (well, both are URIs...).

 PS: Yes, `$uploads['basedir']` contains mixed directory separators. That's
 another thing.

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


More information about the wp-trac mailing list