<commit_before><?php

namespace Kibo\Phast\Filters\HTML;

use Kibo\Phast\ValueObjects\URL;

class CSSImagesOptimizationServiceHTMLFilter extends ImagesOptimizationServiceHTMLFilter {

    public function transformHTMLDOM(\DOMDocument $document) {
        $styleTags = $document->getElementsByTagName('style');
        /** @var \DOMElement $styleTag */
        foreach ($styleTags as $styleTag) {
            $styleTag->textContent = $this->rewriteStyle($styleTag->textContent);
        }

        $styleAttrs = (new \DOMXPath($document))->query('//@style');
        /** @var \DOMAttr $styleAttr */
        foreach ($styleAttrs as $styleAttr) {
            $styleAttr->value = htmlspecialchars($this->rewriteStyle($styleAttr->value));
        }
    }

    private function rewriteStyle($styleContent) {
        return preg_replace_callback(
            '~
                (
                    \b (?: image | background ):
                    [^;}]*
                    \b url \( [:\'"]?
                )
                (
                    [^\'")] +
                )
            ~xi',
            function ($matches) {
                $params = ['src' => (string) URL::fromString($matches[2])->withBase($this->baseUrl)];
                return $matches[1] . $this->makeSignedUrl($this->serviceUrl, $params, $this->signature);
            },
            $styleContent
        );
    }

}<commit_msg>Remove extraneous colon from url(...) regex<commit_after><?php

namespace Kibo\Phast\Filters\HTML;

use Kibo\Phast\ValueObjects\URL;

class CSSImagesOptimizationServiceHTMLFilter extends ImagesOptimizationServiceHTMLFilter {

    public function transformHTMLDOM(\DOMDocument $document) {
        $styleTags = $document->getElementsByTagName('style');
        /** @var \DOMElement $styleTag */
        foreach ($styleTags as $styleTag) {
            $styleTag->textContent = $this->rewriteStyle($styleTag->textContent);
        }

        $styleAttrs = (new \DOMXPath($document))->query('//@style');
        /** @var \DOMAttr $styleAttr */
        foreach ($styleAttrs as $styleAttr) {
            $styleAttr->value = htmlspecialchars($this->rewriteStyle($styleAttr->value));
        }
    }

    private function rewriteStyle($styleContent) {
        return preg_replace_callback(
            '~
                (
                    \b (?: image | background ):
                    [^;}]*
                    \b url \( [\'"]?
                )
                (
                    [^\'")] +
                )
            ~xi',
            function ($matches) {
                $params = ['src' => (string) URL::fromString($matches[2])->withBase($this->baseUrl)];
                return $matches[1] . $this->makeSignedUrl($this->serviceUrl, $params, $this->signature);
            },
            $styleContent
        );
    }

}
{'fraction_non_alphanumeric': 0.14542887398517473, 'fraction_numerical': 0.0014119308153900459, 'mean_word_length': 1.8482412060301507, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3106819', 'n_tokens_mistral': 794, 'n_tokens_neox': 750, 'n_words': 123}