Avoids incorrect results when `url_to_postid()` checking is not strict enough. Adds a bunch of Unit Tests for `url_to_postid()', which is currently only tested lightly in some XML-RPC tests.

Props gcorne, gradyetc.
Fixes #20560.


Built from https://develop.svn.wordpress.org/trunk@25258


git-svn-id: http://core.svn.wordpress.org/trunk@25226 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2013-09-05 17:29:13 +00:00
parent d041c830bc
commit d03b6f9df5
1 changed files with 4 additions and 4 deletions

View File

@ -324,14 +324,14 @@ function url_to_postid($url) {
if ( !$wp_rewrite->using_index_permalinks() ) if ( !$wp_rewrite->using_index_permalinks() )
$url = str_replace( $wp_rewrite->index . '/', '', $url ); $url = str_replace( $wp_rewrite->index . '/', '', $url );
if ( false !== strpos($url, home_url()) ) { if ( false !== strpos( trailingslashit( $url ), home_url( '/' ) ) ) {
// Chop off http://domain.com // Chop off http://domain.com/[path]
$url = str_replace(home_url(), '', $url); $url = str_replace(home_url(), '', $url);
} else { } else {
// Chop off /path/to/blog // Chop off /path/to/blog
$home_path = parse_url(home_url()); $home_path = parse_url( home_url( '/' ) );
$home_path = isset( $home_path['path'] ) ? $home_path['path'] : '' ; $home_path = isset( $home_path['path'] ) ? $home_path['path'] : '' ;
$url = str_replace($home_path, '', $url); $url = preg_replace( sprintf( '#^%s#', preg_quote( $home_path ) ), '', trailingslashit( $url ) );
} }
// Trim leading and lagging slashes // Trim leading and lagging slashes