fix hasName method for empty name cases

This commit is contained in:
Anton Lavrenov
2019-03-21 07:43:58 -05:00
parent ef30c1b6b9
commit f9c60c99e1
5 changed files with 29 additions and 5 deletions

View File

@@ -1987,9 +1987,18 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
* node.name('red');
* node.hasName('red'); // return true
* node.hasName('selected'); // return false
* node.hasName(''); // return false
*/
hasName(name) {
var names = (this.name() || '').split(/\s/g);
if (!name) {
return false;
}
const fullName = this.name();
if (!fullName) {
return false;
}
// if name is '' the "names" will be [''], so I added extra check above
var names = (fullName || '').split(/\s/g);
return names.indexOf(name) !== -1;
}
/**