xwp / wp-dependency-minification

Dependency Minification plugin for WordPress
http://wordpress.org/plugins/dependency-minification/
52 stars 10 forks source link

Filter added to rewrite_rules_array breaks the minification rewrite regex #48

Closed c3mdigital closed 10 years ago

c3mdigital commented 10 years ago

Still investigating whether the problem is with the filter added to rewrite_rules_array or how the regex is written in the plugin.

On a site where a region and language slug are appended to every url rewrite rules are added to the rewrite_rules_array to determine the region and language from the given url.

Filter function


    static function _filter_rewrite_rules_array( $initial_rules ) {
        $region_lang_pattern_prefix = sprintf( '%s/', self::_get_region_url_pattern() );
        $new_rules[$region_lang_pattern_prefix . '?$'] = 'index.php?selected_region=$matches[1]&selected_language=$matches[2]';
        foreach ( $initial_rules as $pattern => $query ) {
            self::$match_count = 2;
            // Find all occurrences of $matches[x] and increment x by 2 since we are pushing the 2 query_var match rules in front of all existing rules. Kind of hackish but it works.
            $query = preg_replace_callback( '/\\d/ui', array( __CLASS__, 'increment_matches' ), $query );
            $query = str_ireplace( 'index.php?', 'index.php?selected_region=$matches[1]&selected_language=$matches[2]&', $query );
            $new_rules[$region_lang_pattern_prefix . $pattern] = $query;
        }
        return $new_rules;
    }

        static function increment_matches( $match ) {
        return (int)$match + self::$match_count++;
    }

This causes the rule entry for minify to be written as follows:

[(on|ab|bc)/(en|yue-can|it|cmn|pa|southasian)/^_minify/([^/]+?)\.([0-9a-f]+)(?:\.([0-9a-f]+))?\.(css|js)] = index.php?selected_region=$matches[1]&selected_language=$matches[2]&depmin_handles=$matches[3]&depmin_src_hash=$matches[4]&depmin_ver_hash=$matches[5]&depmin_file_ext=$matches[6]&
nash-ye commented 10 years ago

hmm,, there are filters in get_option too.. could you give us more info about the bug?!

c3mdigital commented 10 years ago

After further investigation the bug is actually in the minify rewrite rule added. I'm editing this issue.