markjaquith / WP-Stack

A toolkit for creating professional WordPress deployments
1.11k stars 123 forks source link

CDN Regex URL Replacement misses URLs prefaced with parenthesis #25

Open phikai opened 10 years ago

phikai commented 10 years ago

In a case where you're defining a background url or other similar CSS case with the URL defined inside of a parenthesis, the regex misses these URLs. Example:

background: url('wp-content/themes/pax/img/icon-link-btn.png') no-repeat !important;

background: url("http://DOMAIN.COM/wp-content/uploads/2013/01/logo-blue.png") no-repeat scroll center center transparent !important;
clifgriffin commented 7 years ago

Remove the two equal signs = from the regex patterns fixes this.

This might make the RegEx a little more wide open, but the extension filter seems pretty protective. I can't really imagine a scenario where this breaks it.

In other words this:

    public function filter( $content ) {
        return preg_replace( "#=([\"'])(https?://{$this->site_domain})?/([^/](?:(?!\\1).)+)\.(" . implode( '|', $this->extensions ) . ")(\?((?:(?!\\1).)+))?\\1#", '=$1//' . $this->cdn_domain . '/$3.$4$5$1', $content );
    }

Becomes:

    public function filter( $content ) {
        return preg_replace( "#([\"'])(https?://{$this->site_domain})?/([^/](?:(?!\\1).)+)\.(" . implode( '|', $this->extensions ) . ")(\?((?:(?!\\1).)+))?\\1#", '$1//' . $this->cdn_domain . '/$3.$4$5$1', $content );
    }