Skip to content

Commit

Permalink
Regex escape mathes before using them as regex to prevent delimiter p…
Browse files Browse the repository at this point in the history
…roblems.
  • Loading branch information
barrykooij committed Oct 21, 2014
1 parent 153664d commit 4d3fbaa
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions includes/wc-core-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,10 @@ function wc_fix_rewrite_rules( $rules ) {
$product_permalink = empty( $permalinks['product_base'] ) ? _x( 'product', 'slug', 'woocommerce' ) : $permalinks['product_base'];

// Fix the rewrite rules when the product permalink have %product_cat% flag
if ( preg_match( '`/(?:.+)(/%product_cat%)`' , $product_permalink, $matches ) ) {
if ( preg_match( '`/(.+)(/%product_cat%)`' , $product_permalink, $matches ) ) {
foreach ( $rules as $rule => $rewrite ) {
if ( preg_match( '/^' . $matches[0] . '\/\(/', $rule ) && preg_match( '/^(index\.php\?product_cat)(?!(.*product))/', $rewrite ) ) {

if ( preg_match( '`^' . preg_quote( $matches[1], '`' ) . '/\(`', $rule ) && preg_match( '/^(index\.php\?product_cat)(?!(.*product))/', $rewrite ) ) {
unset( $rules[ $rule ] );
}
}
Expand Down

0 comments on commit 4d3fbaa

Please sign in to comment.