diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php
index 1e8c598..750e100 100644
|
|
function backslashit($string) { |
1482 | 1482 | /** |
1483 | 1483 | * Appends a trailing slash. |
1484 | 1484 | * |
1485 | | * Will remove trailing slash if it exists already before adding a trailing |
| 1485 | * Will remove trailing slash or backslash if it exists already before adding a trailing |
1486 | 1486 | * slash. This prevents double slashing a string or path. |
1487 | 1487 | * |
1488 | 1488 | * The primary use of this is for paths and thus should be used for paths. It is |
1489 | 1489 | * not restricted to paths and offers no specific path support. |
1490 | 1490 | * |
1491 | 1491 | * @since 1.2.0 |
1492 | | * @uses untrailingslashit() Unslashes string if it was slashed already. |
| 1492 | * @uses untrailingslashit() Removes trailing slash or backslash if it exists. |
1493 | 1493 | * |
1494 | 1494 | * @param string $string What to add the trailing slash to. |
1495 | 1495 | * @return string String with trailing slash added. |
1496 | 1496 | */ |
1497 | | function trailingslashit($string) { |
1498 | | return untrailingslashit($string) . '/'; |
| 1497 | function trailingslashit( $string ) { |
| 1498 | return untrailingslashit( $string ) . '/'; |
1499 | 1499 | } |
1500 | 1500 | |
1501 | 1501 | /** |
1502 | | * Removes trailing slash if it exists. |
| 1502 | * Removes trailing slash or backslash if it exists. |
1503 | 1503 | * |
1504 | 1504 | * The primary use of this is for paths and thus should be used for paths. It is |
1505 | 1505 | * not restricted to paths and offers no specific path support. |
1506 | 1506 | * |
1507 | 1507 | * @since 2.2.0 |
1508 | 1508 | * |
1509 | | * @param string $string What to remove the trailing slash from. |
1510 | | * @return string String without the trailing slash. |
| 1509 | * @param string $string What to remove the trailing slash or backslash from. |
| 1510 | * @return string String without the trailing slash or backslash. |
1511 | 1511 | */ |
1512 | | function untrailingslashit($string) { |
1513 | | return rtrim($string, '/'); |
| 1512 | function untrailingslashit( $string ) { |
| 1513 | return rtrim( $string, '/\\' ); |
1514 | 1514 | } |
1515 | 1515 | |
1516 | 1516 | /** |
diff --git tests/phpunit/tests/formatting/Slashit.php tests/phpunit/tests/formatting/Slashit.php
index 9db62a5..04c6d7f 100644
|
|
class Tests_Formatting_Slashit extends WP_UnitTestCase { |
21 | 21 | $this->assertEquals("a", untrailingslashit("a////")); |
22 | 22 | } |
23 | 23 | |
| 24 | function test_removes_trailing_backslashes() { |
| 25 | $this->assertEquals("a", untrailingslashit("a\\")); |
| 26 | $this->assertEquals("a", untrailingslashit("a\\\\\\\\")); |
| 27 | } |
| 28 | |
24 | 29 | function test_adds_trailing_slash() { |
25 | 30 | $this->assertEquals("a/", trailingslashit("a")); |
26 | 31 | } |
… |
… |
class Tests_Formatting_Slashit extends WP_UnitTestCase { |
28 | 33 | function test_does_not_add_trailing_slash_if_one_exists() { |
29 | 34 | $this->assertEquals("a/", trailingslashit("a/")); |
30 | 35 | } |
| 36 | |
| 37 | function test_converts_trailing_backslash_to_slash_if_one_exists() { |
| 38 | $this->assertEquals("a/", trailingslashit("a\\")); |
| 39 | } |
31 | 40 | } |