Skip to content
Browse files

Better error reporting for the ‘uniqueItems’ attribute

  • Loading branch information...
1 parent ec161be commit dd513538f052eb27ef0ecfe1638fa7b2701d08de @Baggz committed Mar 14, 2012
Showing with 11 additions and 1 deletion.
  1. +3 −1 src/engines/json/attributes/uniqueItems.js
  2. +8 −0 src/engines/json/joinPath.js
View
4 src/engines/json/attributes/uniqueItems.js
@@ -20,7 +20,9 @@
if (subIndex !== index) {
if (isEqual(value, subValue)) {
- self.addError();
+ self.addError({
+ property: self.joinPath(property, subIndex)
+ });
}
}
View
8 src/engines/json/joinPath.js
@@ -5,11 +5,19 @@
* @param {string} property
*/
Validation.prototype.joinPath = function(path, property) {
+
+ // If the ‘path’ is undefined (object), convert the path to a string
+ path = path || '';
+
+ // Converts the ‘property’ to a string
+ property = property + '';
+
if (property.match(/^[a-zA-Z]+$/)) {
return (path) ? (path + '.' + property) : property;
} else if (property.match(/\d+/)) {
return path + '[' + property + ']';
} else {
return path + '["' + property + '"]';
}
+
};

0 comments on commit dd51353

Please sign in to comment.
Something went wrong with that request. Please try again.