Permalink
Browse files

adding bounding to string operations so they do not error out

  • Loading branch information...
1 parent e91b0dd commit 5c8ca416fb6e033e549dc80890c70b32729b3cc1 Todd Kennedy committed Jun 4, 2012
Showing with 6 additions and 6 deletions.
  1. +4 −4 README.md
  2. +2 −2 backbone.validator.js
View
@@ -181,16 +181,16 @@ is_key: function(value, obj, attribute){
}
},
-// not too long
+// does the value come in under a max?
max_length: function(value, length, attribute){
- if(!_.isUndefined(value.length) && (value.length > length)){
+ if(!_.isNull(value) && !_.isUndefined(value) && _.has(value, "length") && !_.isUndefined(value.length) && (value.length > length)){
return format("{0} is longer than {1} for {2} ", value, length, attribute);
}
},
-// and not to short
+// does the value meet a minimum requirement
min_length: function(value, length, attribute){
- if(!_.isUndefined(value.length) && (value.length < length)){
+ if(!_.isNull(value) && !_.isUndefined(value) && _.has(value, "length") && !_.isUndefined(value.length) && (value.length < length)){
return format('{0} is shorter than {1} for {2}', value, length, attribute);
}
},
View
@@ -161,14 +161,14 @@ Backbone.Validator.testers = (function(){
// does the value come in under a max?
max_length: function(value, length, attribute){
- if(!_.isUndefined(value.length) && (value.length > length)){
+ if(!_.isNull(value) && !_.isUndefined(value) && _.has(value, "length") && !_.isUndefined(value.length) && (value.length > length)){
return format("{0} is longer than {1} for {2} ", value, length, attribute);
}
},
// does the value meet a minimum requirement
min_length: function(value, length, attribute){
- if(!_.isUndefined(value.length) && (value.length < length)){
+ if(!_.isNull(value) && !_.isUndefined(value) && _.has(value, "length") && !_.isUndefined(value.length) && (value.length < length)){
return format('{0} is shorter than {1} for {2}', value, length, attribute);
}
},

0 comments on commit 5c8ca41

Please sign in to comment.