[wp-trac] [WordPress Trac] #55897: Add tests for path_join()

WordPress Trac noreply at wordpress.org
Fri Jun 3 15:08:45 UTC 2022

#55897: Add tests for path_join()
 Reporter:  karlijnbk                            |       Owner:  karlijnbk
     Type:  enhancement                          |      Status:  assigned
 Priority:  normal                               |   Milestone:  6.1
Component:  General                              |     Version:  trunk
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests dev-        |     Focuses:
  feedback                                       |

Comment (by SergeyBiryukov):

 Replying to [comment:9 SergeyBiryukov]:
 > Looks like you're right about including it in the first return, and we
 should include a test case for a path with multiple slashes.

 A test case was added in [53461].

 Thinking about it some more, I believe the current behavior is correct:
 Windows supports any combination of two or more leading slashes or
 backslashes in network shares:

 * `\\host\share`
 * `\\host/share`
 * `//host\share`
 * `//host/share`
 * `\\\host\share`
 * `\\\host/share`
 * `///host\share`
 * `///host/share`

 So using `return '/' . ltrim( $path, '/' )` in case of an absolute path
 would break it, keeping only a single slash or introducing a mix of
 slashes. We could limit the leading slashes or backslashes to two, but
 that would make the function a bit more complicated without an obvious

 There are a few further enhancements that could be made here:

 * Making sure that `$base` and `$path` are both indeed strings. This could
 use some discussion on how to handle and what to return in case of an
 invalid input.
 * Normalizing the slashes and adding test cases for mixed slashes.
 * Limiting the leading slashes to two and adding test cases for more than
 two slashes.

 I think they should be explored in a new ticket, as this one was focused
 on adding some tests for the current behavior.

Ticket URL: <https://core.trac.wordpress.org/ticket/55897#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list