Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#44660 closed defect (bug) (invalid)

trailingslashit() should end in forward slash, not DIRECTORY_SEPARATOR

Reported by: mnelson4 Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.1
Component: General Keywords: close
Focuses: Cc:


The comment on trailingslashit() says it should add a forward slash, but it actually adds the constant DIRECTORY_SEPARATOR, which on Windows, is a backslash. That creates problems when this method is used for creating URLs from a Windows machine, which is it by plugin_dir_url(), because when those urls are passed to esc_url() the backslash is removed which creates invalid URLs.

Eg, if you have a plugin whose folder is my-plugin, and you created a url from your plugin's main file like plugin_dir_url(__FILE__) . 'my-js-file.js' and enqueue it (which also calls esc_url() on the path provided) you'll end up with an invalid URL being used, like http://mysite.com/wp-content/plugins/my-pluginmy-js-file.js (note the missing slash between my-plugin and my-js-file.js).

So, ending trailingslashit() in a forward slash would both make it consistent with its documentation, and fix URLs generated using plugin_dir_url() when called from Windows machines. (I talk more about my rationale about using DIRECTORY_SEPARATOR vs forward slashes on my blog https://cmljnelson.wordpress.com/2018/07/26/which-way-do-your-slashes-face/)

Change History (2)

#1 @mnelson4
3 years ago

  • Keywords close added
  • Resolution set to invalid
  • Status changed from new to closed

for crying out loud, I made up this whole ticket without noticing I only LOCALLY changed the method to use DIRECTORY_SEPARATOR. All is right in the world. This ticket is a total mistake. 😫

#2 @netweb
3 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.