WordPress.org

Make WordPress Core

#22138 closed defect (bug) (fixed)

wp_basename wrong on Windows Systems

Reported by: sebber Owned by: ryan
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.4.2
Component: Formatting Keywords: has-patch commit
Focuses: Cc:

Description

On Windows System the Directory Seperator is \ instead of Unix /.

So the urlencode in wp_basename() encodes the \ and it is not removed in basename().

WP_basename is not working properly on Windows Systems.

Just take a look in the Support Forum:

http://wordpress.org/support/topic/function-wp_basename-is-wrong-in-windows?replies=3

Attachments (1)

22138.patch (500 bytes) - added by SergeyBiryukov 19 months ago.

Download all attachments as: .zip

Change History (11)

comment:1 sebber19 months ago

Possible Resolution:

function wp_basename( $path, $suffix = ) {
$path = str_replace( '\', '/', $path );
$path = str_replace( '%2F', '/', urlencode( $path ) );
return urldecode( basename( $path ), $suffix );

}

Version 0, edited 19 months ago by sebber (next)

SergeyBiryukov19 months ago

comment:2 SergeyBiryukov19 months ago

  • Keywords has-patch needs-unit-tests added; needs-patch removed
  • Milestone changed from Awaiting Review to 3.5

Confirmed. wp_basename() is mostly used on attachment URLs in core, which is why, I guess, we didn't catch this earlier.

comment:3 SergeyBiryukov19 months ago

  • Summary changed from wp_basname wrong on Windows Systems to wp_basename wrong on Windows Systems

comment:4 sebber19 months ago

I checked your solution. It seems all right. Thank you

comment:5 knutsp19 months ago

  • Cc knut@… added

comment:6 bpetty18 months ago

  • Keywords needs-unit-tests removed

I added unit tests for wp_basename for this situation.

comment:7 bpetty18 months ago

Obviously, I also tested, and 22138.patch works.

Last edited 18 months ago by bpetty (previous) (diff)

comment:8 bpetty18 months ago

  • Cc bpetty added

comment:9 nacin18 months ago

  • Keywords commit added

comment:10 ryan18 months ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [22310]:

Fix wp_basename() for Windows by replacing %5C with /.

Props SergeyBiryukov
fixes #22138

Note: See TracTickets for help on using tickets.