From 26281c21aa994161f0f14894e0d53f5b8ef4921e Mon Sep 17 00:00:00 2001 From: Norbert Csaba Herczeg Date: Wed, 16 Aug 2017 19:46:19 +0200 Subject: [PATCH 1/2] fix Cannot read property 'indexOf' of undefined The `.rules` property could be an empty string in which case the code dies because it uses `self.validatorAttrs.validation` which could be undefined, therefore the `.indexOf` check fails. This fixes TypeError: Cannot read property 'indexOf' of undefined. --- src/validation-common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validation-common.js b/src/validation-common.js index 8b83b95..bb818af 100644 --- a/src/validation-common.js +++ b/src/validation-common.js @@ -178,7 +178,7 @@ angular self = analyzeElementAttributes(self); // get the rules(or validation), inside directive it's named (validation), inside service(rules) - var rules = self.validatorAttrs.rules || self.validatorAttrs.validation; + var rules = self.validatorAttrs.hasOwnProperty('rules') ? self.validatorAttrs.rules : self.validatorAttrs.validation; // We first need to see if the validation holds a custom user regex, if it does then deal with it first // So why deal with it separately? Because a Regex might hold pipe '|' and so we don't want to mix it with our regular validation pipe From 68e0e172806c2e6745ebd9b4b9327afcd03cac28 Mon Sep 17 00:00:00 2001 From: Norbert Csaba Herczeg Date: Wed, 16 Aug 2017 19:52:10 +0200 Subject: [PATCH 2/2] even better failsafe --- src/validation-common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validation-common.js b/src/validation-common.js index bb818af..a5d2657 100644 --- a/src/validation-common.js +++ b/src/validation-common.js @@ -178,7 +178,7 @@ angular self = analyzeElementAttributes(self); // get the rules(or validation), inside directive it's named (validation), inside service(rules) - var rules = self.validatorAttrs.hasOwnProperty('rules') ? self.validatorAttrs.rules : self.validatorAttrs.validation; + var rules = self.validatorAttrs.rules || self.validatorAttrs.validation || ''; // We first need to see if the validation holds a custom user regex, if it does then deal with it first // So why deal with it separately? Because a Regex might hold pipe '|' and so we don't want to mix it with our regular validation pipe