Make WordPress Core

Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#23175 closed enhancement (fixed)

Make get_home_path() return consistent slashes

Reported by: sergeybiryukov's profile SergeyBiryukov Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 3.6 Priority: normal
Severity: normal Version:
Component: Filesystem API Keywords: has-patch
Focuses: Cc:

Description (last modified by SergeyBiryukov)

As noted in ticket:23073:40, get_home_path() doesn't return consistent slashes.

If home and siteurl are identical, it falls back to ABSPATH:

C:\wamp\www\multitest/

If home and siteurl are different:

C:/wamp/www/wordpress/test_subd/ 

Attachments (3)

23175.patch (1.3 KB) - added by SergeyBiryukov 12 years ago.
23175.2.patch (1.2 KB) - added by SergeyBiryukov 12 years ago.
23175.3.patch (2.1 KB) - added by Marventus 11 years ago.
Fixes slash inconsistencies in ABSPATH constant

Download all attachments as: .zip

Change History (15)

#1 @SergeyBiryukov
12 years ago

I've reviewed all the instances of get_home_path() in core to make sure both types of slashes are allowed there (since it currently returns both types anyway).

It's mostly used in file_exists() and win_is_writable() checks, which is fine.

Last edited 12 years ago by SergeyBiryukov (previous) (diff)

#2 @SergeyBiryukov
12 years ago

  • Description modified (diff)

#3 @SergeyBiryukov
12 years ago

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

In 23669:

Make get_home_path() return consistent slashes. fixes #23175.

#4 follow-up: @bananastalktome
12 years ago

  • Cc bananastalktome@… added
  • Keywords needs-unit-tests added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Breaks unit test test_get_home_path in tests/admin/includesFile.php

1) Tests_Admin_includesFile::test_get_home_path
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'D:\root\vhosts\site\httpdocs/'
+'D:/root/vhosts/site/httpdocs/'

(I'm reopening the ticket because of this, which I think is the proper thing to do in these cases. Please let me know if this is not what I should do.)

#5 @SergeyBiryukov
12 years ago

In 1244/tests:

Update get_home_path() test to reflect the change in [WP23669]. see #23175.

#6 in reply to: ↑ 4 @SergeyBiryukov
12 years ago

  • Keywords needs-unit-tests removed
  • Resolution set to fixed
  • Status changed from reopened to closed

Replying to bananastalktome:

I'm reopening the ticket because of this, which I think is the proper thing to do in these cases.

It is, thanks.

@Marventus
11 years ago

Fixes slash inconsistencies in ABSPATH constant

#7 @Marventus
11 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Could this have come from the various

define('ABSPATH', dirname(__FILE__).'/');

commands scaretted accross multiple files? I took the liberty of creating a diff.

#8 @Marventus
11 years ago

  • Keywords dev-feedback added

#9 @SergeyBiryukov
11 years ago

  • Keywords dev-feedback removed
  • Resolution set to fixed
  • Status changed from reopened to closed

Yes, the trailing slash in ABSPATH is inconsistent in Windows, but it's out of scope for this ticket, and it's not really an issue, since Windows allows to use both types of slashes.

23175.3.patch would make the slashes inconsistent on non-Windows installs.

#10 @Marventus
11 years ago

it's not really an issue, since Windows allows to use both types of slashes

Well, it could be if you are doing path string comparisons. What if we used DIRECTORY_SEPARATOR instead?

define('ABSPATH', dirname(__FILE__).DIRECTORY_SEPARATOR);

Would that address non-Windows OSs?

it's out of scope for this ticket

If you agree with the above, should I create a new ticket and update the diff?
Thanks!

Version 2, edited 11 years ago by Marventus (previous) (next) (diff)

#11 @SergeyBiryukov
11 years ago

I'd suggest to normalize the slashes with str_replace( '\\', '/', ... ) before doing any string manipulations. This is what the core does in a few functions.

Using DIRECTORY_SEPARATOR was previously discussed in #15598, #17494, #20849, and #22267. The consensus in each ticket was that it's not needed.

Last edited 11 years ago by SergeyBiryukov (previous) (diff)

#12 @Marventus
11 years ago

Ok, no worries, and thanks for the detailed answer!

Note: See TracTickets for help on using tickets.