mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-13 22:41:32 -05:00
Merge pull request #3525 from jaswilli/issue-3510
Sanity check page parameter used in findPage
This commit is contained in:
commit
063bd3536b
4 changed files with 34 additions and 7 deletions
|
@ -283,7 +283,11 @@ Post = ghostBookshelf.Model.extend({
|
||||||
authorInstance = options.author !== undefined ? User.forge({slug: options.author}) : false;
|
authorInstance = options.author !== undefined ? User.forge({slug: options.author}) : false;
|
||||||
|
|
||||||
if (options.limit) {
|
if (options.limit) {
|
||||||
options.limit = parseInt(options.limit) || 15;
|
options.limit = parseInt(options.limit, 10) || 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.page) {
|
||||||
|
options.page = parseInt(options.page, 10) || 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
options = this.filterOptions(options, 'findPage');
|
options = this.filterOptions(options, 'findPage');
|
||||||
|
@ -400,7 +404,7 @@ Post = ghostBookshelf.Model.extend({
|
||||||
meta = {},
|
meta = {},
|
||||||
data = {};
|
data = {};
|
||||||
|
|
||||||
pagination.page = parseInt(options.page, 10);
|
pagination.page = options.page;
|
||||||
pagination.limit = options.limit;
|
pagination.limit = options.limit;
|
||||||
pagination.pages = calcPages === 0 ? 1 : calcPages;
|
pagination.pages = calcPages === 0 ? 1 : calcPages;
|
||||||
pagination.total = totalPosts;
|
pagination.total = totalPosts;
|
||||||
|
|
|
@ -164,7 +164,11 @@ User = ghostBookshelf.Model.extend({
|
||||||
roleInstance = options.role !== undefined ? Role.forge({name: options.role}) : false;
|
roleInstance = options.role !== undefined ? Role.forge({name: options.role}) : false;
|
||||||
|
|
||||||
if (options.limit && options.limit !== 'all') {
|
if (options.limit && options.limit !== 'all') {
|
||||||
options.limit = parseInt(options.limit) || 15;
|
options.limit = parseInt(options.limit, 10) || 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.page) {
|
||||||
|
options.page = parseInt(options.page, 10) || 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
options = this.filterOptions(options, 'findPage');
|
options = this.filterOptions(options, 'findPage');
|
||||||
|
@ -268,7 +272,7 @@ User = ghostBookshelf.Model.extend({
|
||||||
meta = {},
|
meta = {},
|
||||||
data = {};
|
data = {};
|
||||||
|
|
||||||
pagination.page = parseInt(options.page, 10);
|
pagination.page = options.page;
|
||||||
pagination.limit = options.limit;
|
pagination.limit = options.limit;
|
||||||
pagination.pages = calcPages === 0 ? 1 : calcPages;
|
pagination.pages = calcPages === 0 ? 1 : calcPages;
|
||||||
pagination.total = totalUsers;
|
pagination.total = totalUsers;
|
||||||
|
|
|
@ -105,7 +105,6 @@ describe('Post Model', function () {
|
||||||
}).catch(done);
|
}).catch(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('can findOne', function (done) {
|
it('can findOne', function (done) {
|
||||||
var firstPost;
|
var firstPost;
|
||||||
|
|
||||||
|
@ -157,7 +156,6 @@ describe('Post Model', function () {
|
||||||
}).catch(done);
|
}).catch(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('can add, defaults are all correct', function (done) {
|
it('can add, defaults are all correct', function (done) {
|
||||||
var createdPostUpdatedDate,
|
var createdPostUpdatedDate,
|
||||||
newPost = testUtils.DataGenerator.forModel.posts[2],
|
newPost = testUtils.DataGenerator.forModel.posts[2],
|
||||||
|
@ -395,7 +393,6 @@ describe('Post Model', function () {
|
||||||
}).catch(done);
|
}).catch(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('can findPage, with various options', function (done) {
|
it('can findPage, with various options', function (done) {
|
||||||
testUtils.fixtures.insertMorePosts().then(function () {
|
testUtils.fixtures.insertMorePosts().then(function () {
|
||||||
|
|
||||||
|
@ -445,6 +442,7 @@ describe('Post Model', function () {
|
||||||
done();
|
done();
|
||||||
}).catch(done);
|
}).catch(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can findPage for tag, with various options', function (done) {
|
it('can findPage for tag, with various options', function (done) {
|
||||||
testUtils.fixtures.insertMorePosts().then(function () {
|
testUtils.fixtures.insertMorePosts().then(function () {
|
||||||
|
|
||||||
|
@ -490,6 +488,17 @@ describe('Post Model', function () {
|
||||||
done();
|
done();
|
||||||
}).catch(done);
|
}).catch(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can NOT findPage for a page that overflows the datatype', function (done) {
|
||||||
|
PostModel.findPage({ page: 5700000000055345439587894375457849375284932759842375894372589243758947325894375894275894275894725897432859724309 })
|
||||||
|
.then(function (paginationResult) {
|
||||||
|
should.exist(paginationResult.meta);
|
||||||
|
|
||||||
|
paginationResult.meta.pagination.page.should.be.a.Number;
|
||||||
|
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -215,6 +215,16 @@ describe('User Model', function run() {
|
||||||
}).catch(done);
|
}).catch(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can NOT findPage for a page that overflows the datatype', function (done) {
|
||||||
|
UserModel.findPage({ page: 5700000000055345439587894375457849375284932759842375894372589243758947325894375894275894275894725897432859724309 })
|
||||||
|
.then(function (paginationResult) {
|
||||||
|
should.exist(paginationResult.meta);
|
||||||
|
|
||||||
|
paginationResult.meta.pagination.page.should.be.a.Number;
|
||||||
|
|
||||||
|
done();
|
||||||
|
}).catch(done);
|
||||||
|
});
|
||||||
|
|
||||||
it('can findOne', function (done) {
|
it('can findOne', function (done) {
|
||||||
var firstUser;
|
var firstUser;
|
||||||
|
|
Loading…
Reference in a new issue