Make WordPress Core

Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#23175 closed enhancement (fixed)

Make get_home_path() return consistent slashes

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

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 14 years ago.
23175.2.patch (1.2 KB ) - added by SergeyBiryukov 13 years ago.
23175.3.patch (2.1 KB ) - added by Marventus 13 years ago.
Fixes slash inconsistencies in ABSPATH constant

Download all attachments as: .zip

Change History (15)

#1 @SergeyBiryukov
14 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 14 years ago by SergeyBiryukov (previous) (diff)

#2 @SergeyBiryukov
14 years ago

  • Description modified (diff)

#3 @SergeyBiryukov
13 years ago

  • Owner set to SergeyBiryukov
  • Resolutionfixed
  • Status newclosed

In 23669:

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

#4 follow-up: @bananastalktome
13 years ago

  • Cc bananastalktome@… added
  • Keywords needs-unit-tests added
  • Resolution fixed
  • Status closedreopened

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
13 years ago

In 1244/tests:

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

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

  • Keywords needs-unit-tests removed
  • Resolutionfixed
  • Status reopenedclosed

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
13 years ago

Fixes slash inconsistencies in ABSPATH constant

#7 @Marventus
13 years ago

  • Resolution fixed
  • Status closedreopened

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
13 years ago

  • Keywords dev-feedback added

#9 @SergeyBiryukov
13 years ago

  • Keywords dev-feedback removed
  • Resolutionfixed
  • Status reopenedclosed

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
13 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 manipulations. 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!

Last edited 13 years ago by Marventus (previous) (diff)

#11 @SergeyBiryukov
13 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 13 years ago by SergeyBiryukov (previous) (diff)

#12 @Marventus
13 years ago

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

Note: See TracTickets for help on using tickets.