Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

fix(colors): handle null or undefined in md-colors #11673

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion src/components/colors/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
* @returns rgba color string
Copy link
Member

Choose a reason for hiding this comment

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

This should be updated to be

* @returns {string} rgba color string or empty string

*/
function parseColor(color, contrast) {
if(!color) {
Copy link
Member

Choose a reason for hiding this comment

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

Please run npm run lint -- --fix to get these changes to pass the lint checks.

return '';
}
contrast = contrast || false;
var rgbValues = $mdTheming.PALETTES[color.palette][color.hue];

Expand Down Expand Up @@ -171,6 +174,9 @@
* For the evaluated expression, extract the color parts into a hash map
*/
function extractColorOptions(expression) {
if(!expression) {
return undefined;
Copy link
Member

Choose a reason for hiding this comment

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

If this is going to start returning undefined, then we need to make sure that callers like interpolateColors() on lines 154 and 156 don't call parseColor(undefined).

}
var parts = expression.split('-');
var hasTheme = angular.isDefined($mdTheming.THEMES[parts[0]]);
var theme = hasTheme ? parts.splice(0, 1)[0] : $mdTheming.defaultTheme();
Expand Down Expand Up @@ -316,7 +322,7 @@
if (mdThemeController) {
Object.keys(colors).forEach(function (prop) {
var color = colors[prop];
if (!$mdColors.hasTheme(color)) {
if (color && !$mdColors.hasTheme(color)) {
colors[prop] = (theme || mdThemeController.$mdTheme) + '-' + color;
}
});
Expand Down