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

remove spaces from color hex codes #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AJFunk
Copy link

@AJFunk AJFunk commented Feb 3, 2017

Having spaces in hex codes breaks css assertions like $expect('h2').to.have.css('color', 'blue');

Copy link

@mdoliner mdoliner left a comment

Choose a reason for hiding this comment

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

Sorry for the delay - we didn't see this come in! Thanks for contributing to jquery-expect!

@@ -460,11 +460,11 @@
*/

function rgb2hex (rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
return "#" +
rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);

Choose a reason for hiding this comment

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

rgba to hex would be a little more complicated - we shouldn't accept 'a' here since it won't correctly convert the color - it would be better to create a separate function rgba2hex with the correct logic instead of trying to overload this one

@@ -460,11 +460,11 @@
*/

function rgb2hex (rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
return "#" +
rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);

Choose a reason for hiding this comment

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

I believe a more concise way to accomplish what you are trying to accomplish with [\s+]? would be \s*

rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
return "#" +
rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
return (rgb && rgb.length === 4) ? "#" +

Choose a reason for hiding this comment

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

By nature of there being 3 capturing groups, a match will always have a length of 4 - can you elaborate on what is added by this check

rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
return "#" +
rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
return (rgb && rgb.length === 4) ? "#" +

Choose a reason for hiding this comment

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

Putting error handling in for a non-match I think is a good idea - however I don't think it should silently fail like this - feel free to add a more explicit error to be thrown than the default, but I don't think returning an empty string should be expected functionality

@CLAassistant
Copy link

CLAassistant commented Nov 11, 2019

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

3 participants