Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

handle boolean types in a graceful manner

  • Loading branch information...
commit 9e3c5d4f7a7b580c8344c63b249359216be8c877 1 parent a217370
@rsms authored
Showing with 11 additions and 2 deletions.
  1. +11 −2 oui/util.js
View
13 oui/util.js
@@ -221,11 +221,20 @@ exports.sanitizeInput = function (params, dst, accepts) {
value = Number(value);
type = 'number';
ok = !isNaN(value);
+ } else if (def.type.substr(0,4) === 'bool') {
+ if (type === 'string') {
+ value = (value === 'true' || value === '1' || value === 'on' || value === 'yes');
+ } else {
+ value = !!value;
+ }
+ type = 'boolean';
+ ok = true; // can't fail
} else {
- ok = false;
+ ok = (def.type === type);
}
if (!ok) {
- return mk400err('Bad type of parameter "'+k+'". Expected '+def.type);
+ return mk400err('Bad type of parameter "'+k+'". Expected '+def.type+
+ ' but got '+type);
}
}
// trim strings
Please sign in to comment.
Something went wrong with that request. Please try again.