[wp-trac] [WordPress Trac] #23689: get_blogaddress_by_name() fails to return address for sites whose names begin with a number
WordPress Trac
noreply at wordpress.org
Mon Mar 4 18:04:41 UTC 2013
#23689: get_blogaddress_by_name() fails to return address for sites whose names
begin with a number
-----------------------------+--------------------------
Reporter: dllh | Type: defect (bug)
Status: new | Priority: normal
Milestone: Awaiting Review | Component: Multisite
Version: trunk | Severity: normal
Keywords: has-patch |
-----------------------------+--------------------------
In {{{get_blogaddress_by_name()}}}, we use a backreference to insert the
passed {{{$blogname}}} into the return from {{{network_home_url()}}} when
the site is a subdomain install. When the subdomain begins with a digit,
the first digit is clipped off of the name because of the way
{{{preg_replace()}}} handles backreferences. From
[http://php.net/preg_replace php docs]:
{{{When working with a replacement pattern where a backreference is
immediately followed by another number (i.e.: placing a literal number
immediately after a matched pattern), you cannot use the familiar \\1
notation for your backreference. \\11, for example, would confuse
preg_replace() since it does not know whether you want the \\1
backreference followed by a literal 1, or the \\11 backreference followed
by nothing. In this case the solution is to use \${1}1. This creates an
isolated $1 backreference, leaving the 1 as a literal.}}}
Basically, the leading digit in the passed {{{$blogname}}} is being
interpreted at present as an additional digit in the backreference name,
so that the backreference becomes invalid. This also seems to cause the
first digit to be stripped off of {{{$blogname}}}.
This code landed three years ago in [14703].
The attached patch uses php's recommended syntax for such cases. I tested
the fix in a multisite install by writing the following plugin and testing
it both with and without the patch:
{{{
function dllh_blog_address() {
print '<div class="updated"><p>';
print '<p>Passing the items to the left of the colon to
get_blogaddress_by_name() results in the return on the right.</p>';
print '123foo : ' . get_blogaddress_by_name( '123foo' ) . '<br
/>';
print 'foobar : ' . get_blogaddress_by_name( 'foobar' ) . '<br
/>';
print '</p></div>';
}
// Now we set that function up to execute when the admin_notices action is
called
add_action( 'admin_notices', 'dllh_blog_address' );
}}}
Screen shots of the output from both are attached.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/23689>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list