jsdom / cssstyle

A Node.js implementation of the CSS Object Model CSSStyleDeclaration interface
MIT License
109 stars 70 forks source link

CSS Parser: rgba test incorrect #92

Closed AE1NS closed 5 years ago

AE1NS commented 5 years ago

Hello,

is this library used by the Chrome audit PWA check? I landed here because the audit did not recognize my theme-color (meta tag in head area) rgba value. I just checked 'CSSStyleDeclaration/lib/parsers.js' and the part:

res = colorRegEx3.exec(val);
if (res !== null) {
    parts = res[1].split(/\s*,\s*/);
    if (parts.length !== 4) {
        return undefined;
    }
    if (
        parts.slice(0, 3).every(percentRegEx.test.bind(percentRegEx)) ||
        parts.every(integerRegEx.test.bind(integerRegEx))
    ) {
        if (numberRegEx.test(parts[3])) {
            return exports.TYPES.COLOR;
        }
    }
    return undefined;
}

seems wrong to me. There is just one case where it returns exports.TYPES.COLOR: rgba(PERCENT,PERCENT,PERCENT,ALPHA); But not i.e.: rgba(NUMBER,NUMBER,NUMBER,ALPHA);

Or am I wrong?

jsakas commented 5 years ago

Hi @AEINSIT, thanks for bringing this up.

It appears that parsers.valueType does not properly return COLOR for any rgba values. Works for rgb only.