Skip to content

preg_replace(): Compilation failed: regular expression is too large at offset ... #4

@CriStaS

Description

@CriStaS

There is an error in cssmgr.php:164 :

    if (preg_match('/@media/',$CSSstr)) { 
        preg_match_all('/@media(.*?)\{(([^\{\}]*\{[^\{\}]*\})+)\s*\}/is',$CSSstr,$m);
        for($i=0; $i<count($m[0]); $i++) {
            if ($this->mpdf->CSSselectMedia && !preg_match('/('.trim($this->mpdf->CSSselectMedia).'|all)/i',$m[1][$i])) { 
                $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$CSSstr);
            }
            else {
                $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/',' '.$m[2][$i].' ',$CSSstr);
            }
        }
    }

On large CSS files with complicated rules it may cause regexp limit when replacing by preg_replace:

exception 'yii\base\ErrorException' with message 'preg_replace(): Compilation failed: regular expression is too large at offset 70187' in .../vendor/kartik-v/mpdf/classes/cssmgr.php:164

... but (as far as I can see) there is no real need in preg_replace() in this place. We have exact text, matched by preg_match_all() and now we can use str_replace() (or mb_str_replace()) to clear it out.

P.S. I don't offer pull request because I can miss something


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions