[wp-trac] [WordPress Trac] #12271: Using # in permalinks breaks preg_match in parse_request
WordPress Trac
wp-trac at lists.automattic.com
Thu Feb 18 08:45:23 UTC 2010
#12271: Using # in permalinks breaks preg_match in parse_request
--------------------------+-------------------------------------------------
Reporter: timsogard | Owner: ryan
Type: defect (bug) | Status: new
Priority: normal | Milestone: Unassigned
Component: Permalinks | Version: 2.9.2
Severity: normal | Keywords:
--------------------------+-------------------------------------------------
When using a hash symbol (#) in a custom permalink structure the
parse_request function fails with the error "Unmatched modifier". This is
due to the pattern being delimited by hash symbols (#s).
The call to preg_match is on lines 210 and 211 in wp-includes/classes.php:
{{{
if (preg_match("#^$match#", $request_match, $matches) ||
preg_match("#^$match#", urldecode($request_match), $matches)) {
// Got a match.
}}}
Suggested, probably weak as it's been a while for me and PHP, fix:
Using str_replace on '#'s into '\#'s.
{{{
if (preg_match("#^" . str_replace("#","\#",$match) . "#",
$request_match, $matches) ||
preg_match("#^" . str_replace("#","\#",$match) . "#",
urldecode($request_match), $matches)) {
// Got a match.
}}}
I am using hashes in my URLs because I am loading my WP blog with an ajax
loader (it loads in a div).
Other possible fixes I don't have the werewithall to test(/benchmark) at
the moment:
use a symbol from the intersection of the sets of "may show up in a URL"
and "is a valid PCRE pattern delimeter" as the pattern delimeter.
wrap $match in preg_quote, which will properly escape any of the regular
expression syntax chars ($, *, ?, etc.)
--
Ticket URL: <http://core.trac.wordpress.org/ticket/12271>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list