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

[parse] Trim input, fixes #196 #197

Merged
merged 4 commits into from
Jul 18, 2022
Merged

[parse] Trim input, fixes #196 #197

merged 4 commits into from
Jul 18, 2022

Conversation

AlainGourves
Copy link
Contributor

@AlainGourves AlainGourves commented Jul 17, 2022

Fixes #196
Parse() should trim input strings to avoid edge cases where leading and trailing spaces cause type error.

let color1 = new Color("red"); // works
let color2 = new Color(" red"); // this doesn't

src/parse.js Outdated
@@ -4,7 +4,7 @@ import ColorSpace from "./space.js";

// CSS color to Color object
export default function parse (str) {
let env = {str};
let env = {"str": str?.trim()};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we may want to coerce to a string here as well (str + "") before trimming.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this?

-let env = {"str": str?.trim()};
+let env = {"str": (str+"")?.trim()};

The parentheses could also be removed (just preference).

Copy link
Member

@LeaVerou LeaVerou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! See comment!

@LeaVerou LeaVerou changed the title [parse] Fixes #196 [parse] Trim input, fixes #196 Jul 18, 2022
@LeaVerou LeaVerou merged commit cf75da2 into color-js:main Jul 18, 2022
@LeaVerou
Copy link
Member

Merged, thanks!

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

Successfully merging this pull request may close these issues.

parse() should trim input strings
3 participants