Skip to content

.clone does not preserve validity #156

@Elberet

Description

@Elberet

Summary:

import Tinycolor from 'npm:tinycolor2';
let invalidColor = new Tinycolor('');
let clonedColor = invalidColor.clone();
let shouldBeTrue = invalidColor.isValid() === clonedColor.isValid();
// however: shouldBeTrue === false!

When an invalid color is cloned as demonstrated, Tinycolor returns a new color using the other color's string representation (tinycolor.js#L213). However, since clone() does not check the subject's validity and toString() ends up outputting an RGB hex-string using the default rgb-values - again, without first checking the object's validity -, the result is typically a valid #000000 color.

While it is acceptable for clones to represent the same state while not being identical internally, the validity of the color object is very much an important part of it's state and should be preserved in clones.

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