Added validation of input color codes

development
David Benson 2019-06-12 10:51:21 +01:00 committed by GitHub
parent 33911ed7e0
commit 76e8e2809b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 4 deletions

View File

@ -204,14 +204,21 @@ var ColorDialog = function(editorUi, color, apply, cancelFn)
var applyBtn = mxUtils.button(mxResources.get('apply'), function()
{
var color = input.value;
ColorDialog.addRecentColor(color, 12);
// https://stackoverflow.com/questions/8027423/how-to-check-if-a-string-is-a-valid-hex-color-representation/8027444
var colorValid = /(^#?[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color);
if (color != 'none' && color.charAt(0) != '#')
if (colorValid)
{
color = '#' + color;
ColorDialog.addRecentColor(color, 12);
if (color != 'none' && color.charAt(0) != '#')
{
color = '#' + color;
}
applyFunction(color);
}
applyFunction(color);
editorUi.hideDialog();
});
applyBtn.className = 'geBtn gePrimaryBtn';