regex bug in dialog with a single textfield, AEM 5.6.1
Hi,
I've just found this bug in my AEM 5.6.1 instance: if a dialog tab has only 1 field and this field is a textfield with a regex property then the author will get the error 'this.regex.test is not a function'. Is this a known bug? if so, what is the recommendation to workaround it?
Bellow I'll put some of the investigation I've done, in case it might help:
I think the culprit is this piece of code (inside function FormatData in file /libs/cq/ui/widgets/source/utils/Util.js):
if (i == "items" && array.length == 1) {
// set single items directly as object
data[i] = array[0];
}
else {
data[i] = array;
}
other parts of the system expect data[i] to be an array, even it has only one element. For an example, the function 'CQ.Util.applyDefaults' has this piece of code:
if (value && typeof value == "object" &&
!(value instanceof Array) && !isCqInstance(value)) {
base[name] = CQ.utils.Util.applyDefaults(base[name], value);
}
as can be seen, the conditional will be evaluated to true and CQ.utils.Util.applyDefaults will be wrongly called. This call will in turn change the value of regex from a RegExp instance to an Object instance.