Skip to content

regex not detected results in broken JS output #23

@futtta

Description

@futtta

Trying to minify this extract of real-world 3rd party JS

x=navigator.vendor,S=navigator.userAgent,C=y(e=>/Edge\/|Edg\//.test(e||S)),le=y(e=>/Firefox/.test(e||S)),ue=y(e=>/Trident|MSIE/.test(e||S)),w=y(e=>/Opera|OPR/.test(e||S)),de=y((e,t)=>(/Chrom/.test(e||S)&&/Google/.test(t||x)||/CriOS/.test(e||S))&&!C(e)&&!w(e)),fe=y(e=>/Chrom|Applechromium/.test(e||S)),pe=y((e,t)=>/Safari/.test(e||S)&&/Apple Computer/.test(t||x)&&!C(e)&&!w(e)),me=y(()=>/WebKit/.test(S)),he=e=>{let t=e.indexOf(Version/); nextline="hi";

results in
x=navigator.vendor,S=navigator.userAgent,C=y(e=>/Edge\/|Edg\ nextline="hi"

due to the regex not being properly detected.

in JSMin.php changing the first test in the isRegexpLiteral function from

        if (false !== strpos("(,=:[!&|?+-~*{;", $this->a)) {
            // we can't divide after these tokens
            return true;
        }

into

        if (false !== strpos("(,=:[!&|?+-~*{;>", $this->a)) {
            // we can't divide after these tokens
            return true;
        }

fixes the problem, but not sure if this is the proper/ best way to solve this? can we divide after > ?

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