Skip to content

Commit

Permalink
ready for 0.2.1, fixes issue with out of range values
Browse files Browse the repository at this point in the history
  • Loading branch information
nullivex committed Jan 31, 2014
1 parent 0aa1086 commit 299a37a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ This allows you to perform custom and complex queries and still make use of the

## Changelog

### 0.2.1
* Fixed issue with plugin crashing with out of range start and limit values.

### 0.2.0
* Added custom `find` object support that can be a direct mongoose query object rather than having
one built automatically.
Expand Down
4 changes: 4 additions & 0 deletions lib/mongoose-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ module.exports = exports = function list(schema,options){
search.start = search.start || 0
search.limit = search.limit || 10
search.sort = search.sort || options.sort || ''
//sanity checks
if(search.start < 0) search.start = 0
if(search.limit < 0) search.limit = 10
//setup searching
if('string' === typeof search.find){
var searchText = new RegExp(search.find,'i')
search.find = {$or: []}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mongoose-list",
"version": "0.2.0",
"version": "0.2.1",
"description": "List plugin for mongoose that allows pagination, filtering, and sorting.",
"homepage": "https://github.com/snailjs/mongoose-list",
"bugs": "https://github.com/snailjs/mongoose-list/issues",
Expand Down
24 changes: 24 additions & 0 deletions test/mongoose-list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,29 @@ describe('MongooseList',function(){
done()
})
})
it('should not fail with a negative start value',function(done){
Model.list({start: -100, limit: 10},function(err,count,results){
if(err) throw err
expect(count).to.equal(100)
expect(results.length).to.equal(10)
done()
})
})
it('should not fail with a negative limit value',function(done){
Model.list({start: 50, limit: -10},function(err,count,results){
if(err) throw err
expect(count).to.equal(100)
expect(results.length).to.equal(10)
done()
})
})
it('should not fail with a negative limit and start value',function(done){
Model.list({start: -50, limit: -10},function(err,count,results){
if(err) throw err
expect(count).to.equal(100)
expect(results.length).to.equal(10)
done()
})
})
})
})

0 comments on commit 299a37a

Please sign in to comment.