Skip to content

Commit

Permalink
Fixes #5706. Separately also adds length check for ObjectId hex strin…
Browse files Browse the repository at this point in the history
…g checker.
  • Loading branch information
wlingke committed Oct 24, 2017
1 parent c6fac06 commit 174ad6c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/schema/documentarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var EventEmitter = require('events').EventEmitter;
var MongooseDocumentArray = require('../types/documentarray');
var SchemaType = require('../schematype');
var Subdocument = require('../types/embedded');
var applyHooks = require('../services/model/applyHooks');
var discriminator = require('../services/model/discriminator');
var util = require('util');
var utils = require('../utils');
Expand Down Expand Up @@ -119,6 +120,8 @@ DocumentArray.prototype.discriminator = function(name, schema) {

this.casterConstructor.discriminators[name] = EmbeddedDocument;

applyHooks(EmbeddedDocument, schema);

return this.casterConstructor.discriminators[name];
};

Expand Down
4 changes: 4 additions & 0 deletions lib/schema/embedded.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var $exists = require('./operators/exists');
var EventEmitter = require('events').EventEmitter;
var SchemaType = require('../schematype');
var Subdocument = require('../types/subdocument');
var applyHooks = require('../services/model/applyHooks');
var castToNumber = require('./operators/helpers').castToNumber;
var discriminator = require('../services/model/discriminator');
var geospatial = require('./operators/geospatial');
Expand Down Expand Up @@ -253,5 +254,8 @@ Embedded.prototype.discriminator = function(name, schema) {
discriminator(this.caster, name, schema);

this.caster.discriminators[name] = _createConstructor(schema);

applyHooks(this.caster.discriminators[name], schema);

return this.caster.discriminators[name];
};
2 changes: 1 addition & 1 deletion lib/schema/objectid.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var SchemaType = require('../schematype'),
*/

function ObjectId(key, options) {
var isKeyHexStr = typeof key === 'string' && /^a-f0-9$/i.test(key);
var isKeyHexStr = typeof key === 'string' && key.length === 24 && /^a-f0-9$/i.test(key);
var suppressWarning = options && options.suppressWarning;
if ((isKeyHexStr || typeof key === 'undefined') && !suppressWarning) {
console.warn('mongoose: To create a new ObjectId please try ' +
Expand Down

0 comments on commit 174ad6c

Please sign in to comment.