[wp-trac] [WordPress Trac] #44660: trailingslashit() should end in forward slash, not DIRECTORY_SEPARATOR

WordPress Trac noreply at wordpress.org
Fri Jul 27 23:55:13 UTC 2018


#44660: trailingslashit() should end in forward slash, not DIRECTORY_SEPARATOR
--------------------------+-----------------------------
 Reporter:  mnelson4      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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/)

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


More information about the wp-trac mailing list