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

Update rgba regex to account for alpha #4006

Merged
merged 3 commits into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/color.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
* @memberOf fabric.Color
*/
// eslint-disable-next-line max-len
fabric.Color.reRGBa = /^rgba?\(\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*(?:\s*,\s*(\d+(?:\.\d+)?)\s*)?\)$/;
fabric.Color.reRGBa = /^rgba?\(\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*,\s*(\d{1,3}(?:\.\d+)?\%?)\s*(?:\s*,\s*((?:\d*\.?\d+)?)\s*)?\)$/;

/**
* Regex matching color in HSL or HSLA formats (ex: hsl(200, 80%, 10%), hsla(300, 50%, 80%, 0.5), hsla( 300 , 50% , 80% , 0.5 ))
Expand Down
8 changes: 8 additions & 0 deletions test/unit/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@
equal(oColor.getAlpha(), 0.5, 'alpha should be set properly');
});

test('fromRgba (with missing 0)', function() {
var originalRgba = 'rgba( 255 , 255 , 255 , .3 )';
var oColor = fabric.Color.fromRgba(originalRgba);
equal(oColor.toRgba(), 'rgba(255,255,255,0.3)');
equal(oColor.toHex(), 'FFFFFF');
equal(oColor.getAlpha(), 0.3, 'alpha should be set properly');
});

test('fromRgba (with whitespaces)', function() {
var originalRgba = 'rgba( 255 , 255 , 255 , 0.5 )';
var oColor = fabric.Color.fromRgba(originalRgba);
Expand Down