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

WordPress Trac noreply at wordpress.org
Tue Mar 22 00:13:26 UTC 2022


#36308: get_attached_file() destroys file paths on Windows
-------------------------------------------------+-------------------------
 Reporter:  Whissi                               |       Owner:  stevenlinx
     Type:  defect (bug)                         |      Status:  assigned
 Priority:  normal                               |   Milestone:  6.0
Component:  Media                                |     Version:  4.4.2
 Severity:  normal                               |  Resolution:
 Keywords:  good-first-bug has-patch has-unit-   |     Focuses:
  tests dev-feedback                             |
-------------------------------------------------+-------------------------
Changes (by davidbaumwald):

 * keywords:  good-first-bug has-patch has-unit-tests => good-first-bug has-
     patch has-unit-tests dev-feedback


Comment:

 Refreshed the latest patch with [https://github.com/WordPress/wordpress-
 develop/pull/2442 PR #2442].  The magic sauce here is the `path_join`
 which uses `path_is_absolute` to make sure the root path isn't duplicated
 in the resulting path.

 I was able to verify this fixes the issue.  To test on Windows:

 1. Create a media item.
 1. Set its `_wp_attached_file` meta to something like
 `C:/WWW/Sites/demo/htdocs/wordpress/wp-
 content/uploads/2016/03/example.jpg`.
 1. Call `get_attached_file` for the attachment ID.

 Pre-patch, you should see a duplicated root in the path, as reported
 originally.  Post-patch, the path should be just what you set in as
 `_wp_attached_file`.

 Since we're messing with file paths here, I'd appreciate a good looks at
 this by some more experienced contributors/committers, even with the added
 tests.

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


More information about the wp-trac mailing list