Ev.
Ev.

Reputation: 1567

preg_match(): Compilation failed PHP WordPress

I made a question the other day but a got a few down votes - possibly because the answer seems obvious. This WordPress blog I am helping has this annoying problem with Permanente Links. Every time it gets activated the following error appears in the website:

preg_match(): Compilation failed: unmatched parentheses at offset 73

I have tried to ask for help in their Support community but that thing is more dead than a morgue and no one is able to help or give support, so I decided to debug it myself and see if I can do something. Problem is I don't have much understanding of PHP and since I am involved in other projects learning PHP just to help with this WordPress thing is not a viable idea. Maybe someone can help here.

            foreach ( (array) $rewrite as $match => $query ) {
                // If the requesting file is the anchor of the match, prepend it to the path info.
                if ( ! empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request )
                    $request_match = $req_uri . '/' . $request;
                // LINE 207
                if ( preg_match( "#^$match#", $request_match, $matches ) || preg_match( "#^$match#", urldecode($request_match), $matches ) ) {

                    if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
                        // This is a verbose page match, let's check to be sure about it.
                        if ( ! get_page_by_path( $matches[ $varmatch[1] ] ) )
                            continue;
                    }

                    // Got a match.
                    $this->matched_rule = $match;
                    break;
                }

This was working perfectly until a few weeks ago when SSL was installed in the Website.

Upvotes: 0

Views: 349

Answers (1)

Simba
Simba

Reputation: 5032

if ( preg_match( "#^$match#", $request_match, $matches ) || preg_match( "#^$match#", urldecode($request_match), $matches ) ) {

There's nothing wrong with the line of code itself; the problem is in what is contained in the variable $match when it is run.

In order for this code to work, $match needs to be a valid regular expression. The error implies that that $match contains an expression which has mis-matched brackets, which would make it an invalid expression.

I don't know where the $match variable is coming from (ie what is setting the variable before the program gets to this line). If it is being fed into the Wordpress code by something you've written, then this is obviously up to you to fix. If it's being generated by some code within Wordpress itself or a third party module, then it is a bug for the developers of that code, which you should probably report to them.

It may also be possible that you've mis-configured the module in some way, in which case fixing the config would solve it, but nevertheless, it would still constitute a bug, as it would mean that the module isn't checking properly for invalid config.

Upvotes: 3

Related Questions