Updating settings with shorter array of swatches causes exception
#287 ouverte le 9 oct. 2020
Métriques du dépôt
- Stars
- (955 stars)
- Métriques de merge PR
- (Aucune PR mergée en 30 j)
Description
When creating an instance with swatches
$('#in').minicolors({
swatches: ['#0000ff', '#ff0000']
});
updating it with a shorter array of swatches
$('#in').minicolors('settings', {
swatches: ['#ff00ff']
});
causes an exception of the form:
Uncaught TypeError: Cannot read property 'match' of undefined
at isRgb (?editor_console=true:1447)
at init (?editor_console=true:789)
at HTMLInputElement.<anonymous> (?editor_console=true:693)
at Function.each (VM229 jquery-2.1.0.js:381)
at jQuery.fn.init.each (VM229 jquery-2.1.0.js:137)
at jQuery.fn.init.minicolors (?editor_console=true:692)
at HTMLInputElement.<anonymous> (?editor_console=true:656)
at Function.each (VM229 jquery-2.1.0.js:381)
at jQuery.fn.init.each (VM229 jquery-2.1.0.js:137)
at jQuery.fn.init.minicolors (?editor_console=true:653)
The problem occurs since Minicolors converts the swatch color strings to RGB objects. When settings are updated, a deep merge is performed. When the passed swatches array is shorter, only the first items are overwritten resulting in an array with mixes strings and RGB objects. The conversion from strings to RGB object is then performed again and fails when it encounters the left over RGB object.
Reproduction case using version 2.3.5: https://jsfiddle.net/majuckvn/5/