Skip to content

Instantly share code, notes, and snippets.

@hugdubois
Created June 8, 2011 13:32
Show Gist options
  • Save hugdubois/1014420 to your computer and use it in GitHub Desktop.
Save hugdubois/1014420 to your computer and use it in GitHub Desktop.
--- node_modules/mongoose/lib/mongoose/schema/number.js 2011-06-08 14:42:22.000000000 +0200
+++ version2 2011-06-08 14:40:37.000000000 +0200
@@ -84,8 +84,11 @@
SchemaNumber.prototype.cast = function (value, doc) {
if (!isNaN(value)){
if (null === value) return value;
- if ('' === value) return null;
- if ('string' === typeof value) value = Number(value);
+ if ('string' === typeof value) {
+ value = value.trim();
+ if ('' === value) return null;
+ value = Number(value);
+ }
if (value instanceof Number || typeof value == 'number' ||
(value.toString && value.toString() == Number(value)))
return new MongooseNumber(value, this.path, doc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment