Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color.isCSSColorString is buggy #1134

Closed
pixelzoom opened this issue Jan 6, 2021 · 3 comments
Closed

Color.isCSSColorString is buggy #1134

pixelzoom opened this issue Jan 6, 2021 · 3 comments
Assignees
Labels

Comments

@pixelzoom
Copy link
Contributor

pixelzoom commented Jan 6, 2021

Color isCSSColorString was added in 4e26f60 for #1115.

This is affecting work in bamboo, and I'll need to work around it.

It's buggy, and these examples are failing:

Color.isCSSColorString( null )
Color.isCSSColorString( undefined )
Color.isCSSColorString( {} )

There's no reason that isCSSColorString should ever fail; it should return true or false.

For example:

> phet.scenery.Color.isCSSColorString( null )
Color.js:812 Uncaught TypeError: Cannot read property 'replace' of null
    at Function.preprocessCSS (Color.js:812)
    at Function.isCSSColorString (Color.js:831)
    at eval (eval at window.assertions.assertFunction (assert.js:25), <anonymous>:1:20)
    at window.assertions.assertFunction (assert.js:25)
    at Color.set (Color.js:90)
    at new Color (Color.js:47)
    at Function.toColor (Color.js:623)
    at <anonymous>:1:20
@pixelzoom
Copy link
Contributor Author

Should Color.isCSSColorString( null ) -> 'transparent' ? That's essentially what PaintDef does.

@pixelzoom
Copy link
Contributor Author

pixelzoom commented Jan 6, 2021

On Slack, @jonathanolson says that isCSSColorString is documented to only support string. If that's the case, please add an assertion. EDIT: That also seems like an unnessary restriction to me.

@jonathanolson
Copy link
Contributor

Added an assertion. Presumably we could have a place checking to see if something is a valid color value if needed (and a type check included there), I'd prefer not to add type-checks in this type of function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants