koa-pagination
Advanced tools
Comparing version 0.3.1 to 1.0.0
## Changelog | ||
### 1.0.0 / 2015-12-10 | ||
- [#25](https://github.com/seegno/koa-pagination/pull/25) Remove usage of `chai` (@franciscocardoso) | ||
- [#24](https://github.com/seegno/koa-pagination/pull/24) Prevent usage of unsafe numbers (@franciscocardoso) | ||
- [#23](https://github.com/seegno/koa-pagination/pull/23) Replace `create-error` with `standard-http-error` (@franciscocardoso) | ||
### 0.3.1 / 2015-02-26 | ||
@@ -4,0 +9,0 @@ - [#21](https://github.com/seegno/koa-pagination/pull/21) Fix readme headers example (@nunorafaelrocha) |
@@ -6,8 +6,23 @@ | ||
var errors = require('create-error'); | ||
const HttpError = require('standard-http-error'); | ||
const util = require('util'); | ||
/** | ||
* Constructor. | ||
*/ | ||
function InvalidConfigurationError() { | ||
HttpError.call(this); | ||
} | ||
/** | ||
* Inherit from `HttpError`. | ||
*/ | ||
util.inherits(InvalidConfigurationError, HttpError); | ||
/** | ||
* Export `InvalidConfigurationError`. | ||
*/ | ||
module.exports = errors('InvalidConfigurationError'); | ||
module.exports = InvalidConfigurationError; |
@@ -6,8 +6,23 @@ | ||
var errors = require('create-error'); | ||
const HttpError = require('standard-http-error'); | ||
const util = require('util'); | ||
/** | ||
* Constructor. | ||
*/ | ||
function MalformedRangeError(message, properties) { | ||
HttpError.call(this, 412, message, properties); | ||
} | ||
/** | ||
* Inherit from `HttpError`. | ||
*/ | ||
util.inherits(MalformedRangeError, HttpError); | ||
/** | ||
* Export `MalformedRangeError`. | ||
*/ | ||
module.exports = errors('MalformedRangeError', { status: 412 }); | ||
module.exports = MalformedRangeError; |
@@ -6,8 +6,23 @@ | ||
var errors = require('create-error'); | ||
const HttpError = require('standard-http-error'); | ||
const util = require('util'); | ||
/** | ||
* Constructor. | ||
*/ | ||
function RangeNotSatisfiableError(message, properties) { | ||
HttpError.call(this, 416, message, properties); | ||
} | ||
/** | ||
* Inherit from `HttpError`. | ||
*/ | ||
util.inherits(RangeNotSatisfiableError, HttpError); | ||
/** | ||
* Export `RangeNotSatisfiableError`. | ||
*/ | ||
module.exports = errors('RangeNotSatisfiableError', { status: 416 }); | ||
module.exports = RangeNotSatisfiableError; |
@@ -11,2 +11,3 @@ | ||
var contentRangeFormat = require('http-content-range-format'); | ||
var isSafeInteger = require('is-safe-integer'); | ||
var rangeSpecifierParser = require('range-specifier-parser'); | ||
@@ -31,3 +32,3 @@ | ||
// Prevent invalid `maximum` value configuration. | ||
if (!_.isFinite(maximum) || maximum <= 0) { | ||
if (!_.isFinite(maximum) || !isSafeInteger(maximum) || maximum <= 0) { | ||
throw new InvalidConfigurationError(); | ||
@@ -52,2 +53,6 @@ } | ||
unit = range.unit; | ||
if (!isSafeInteger(first) || !isSafeInteger(last)) { | ||
throw new RangeNotSatisfiableError(); | ||
} | ||
} | ||
@@ -54,0 +59,0 @@ |
{ | ||
"name": "koa-pagination", | ||
"version": "0.3.1", | ||
"version": "1.0.0", | ||
"description": "Koa Pagination", | ||
@@ -10,11 +10,11 @@ "main": "index.js", | ||
"dependencies": { | ||
"create-error": "0.3.1", | ||
"debug": "2.1.0", | ||
"http-content-range-format": "1.0.0", | ||
"is-safe-integer": "^1.0.1", | ||
"lodash": "2.4.1", | ||
"range-specifier-parser": "0.1.0", | ||
"standard-http-error": "2.0.0", | ||
"util": "0.10.3" | ||
}, | ||
"devDependencies": { | ||
"chai": "1.10.0", | ||
"co-mocha": "1.0.2", | ||
@@ -21,0 +21,0 @@ "co-supertest": "0.0.7", |
@@ -6,3 +6,2 @@ | ||
var chai = require('chai'); | ||
var koa = require('koa'); | ||
@@ -13,4 +12,2 @@ var paginate = require('../'); | ||
chai.should(); | ||
/** | ||
@@ -103,2 +100,13 @@ * Test `paginate`. | ||
it('should give and error if `maximum` is not a safe integer', function *() { | ||
var app = koa(); | ||
app.use(paginate({ maximum: 9007199254740993 })); | ||
yield request(app.listen()) | ||
.get('/') | ||
.expect(500) | ||
.end(); | ||
}); | ||
it('should accept a `Range` header', function *() { | ||
@@ -188,2 +196,26 @@ var app = koa(); | ||
it('should give and error if `first position` is not a safe integer', function *() { | ||
var app = koa(); | ||
app.use(paginate()); | ||
yield request(app.listen()) | ||
.get('/') | ||
.set('Range', 'items=9007199254740992-9007199254740993') | ||
.expect(416) | ||
.end(); | ||
}); | ||
it('should give and error if `last position` is not a safe integer', function *() { | ||
var app = koa(); | ||
app.use(paginate()); | ||
yield request(app.listen()) | ||
.get('/') | ||
.set('Range', 'items=1-9007199254740992') | ||
.expect(416) | ||
.end(); | ||
}); | ||
it('should not allow `last position` value to be higher than `length`', function *() { | ||
@@ -190,0 +222,0 @@ var app = koa(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
19682
11
394
1
7
+ Addedis-safe-integer@^1.0.1
+ Addedstandard-http-error@2.0.0
+ Addedis-safe-integer@1.0.2(transitive)
+ Addedmax-safe-integer@1.0.1(transitive)
+ Addedstandard-error@1.1.0(transitive)
+ Addedstandard-http-error@2.0.0(transitive)
- Removedcreate-error@0.3.1
- Removedcreate-error@0.3.1(transitive)