markjaquith/WP-Stack

CDN Regex URL Replacement misses URLs prefaced with parenthesis

phikai opened this issue · 1 comments

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;

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 );
	}