Smarter fix for , since not all 24-character strings are like MongoDB ids.

This commit is contained in:
Nick Winter 2014-04-11 20:38:34 -07:00
parent 137d2b0fd4
commit fc9d30ccae
2 changed files with 3 additions and 5 deletions
app/models
server/plugins

View file

@ -194,7 +194,7 @@ class CocoModel extends Backbone.Model
return model
@isObjectID: (s) ->
s.length is 24 and s.match(/[a-z0-9]/gi)?.length is 24
s.length is 24 and s.match(/[a-f0-9]/gi)?.length is 24
hasReadAccess: (actor) ->
# actor is a User object

View file

@ -22,13 +22,11 @@ module.exports.NamedPlugin = (schema) ->
schema.methods.checkSlugConflicts = (done) ->
slug = @get('slug')
try
id = mongoose.Types.ObjectId.createFromHexString(slug)
if slug.length is 24 and slug.match(/[a-f0-9]/gi)?.length is 24
err = new Error('Bad name.')
err.response = {message:'cannot be like a MondoDB id, Mr Hacker.', property:'name'}
err.response = {message: 'cannot be like a MongoDB ID, Mr. Hacker.', property: 'name'}
err.code = 422
done(err)
catch e
query = { slug:slug }