mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 12:19:51 +01:00
Fix incorrect middleware execution with unanchored RegExps
fixes #4204 closes #4205
This commit is contained in:
parent
bdc2c973a4
commit
abb7793ae0
|
|
@ -1,6 +1,7 @@
|
|||
unreleased
|
||||
==========
|
||||
|
||||
* Fix incorrect middleware execution with unanchored `RegExp`s
|
||||
* Fix `res.jsonp(obj, status)` deprecation message
|
||||
* Fix typo in `res.is` JSDoc
|
||||
|
||||
|
|
|
|||
|
|
@ -287,6 +287,12 @@ proto.handle = function handle(req, res, out) {
|
|||
|
||||
function trim_prefix(layer, layerError, layerPath, path) {
|
||||
if (layerPath.length !== 0) {
|
||||
// Validate path is a prefix match
|
||||
if (layerPath !== path.substr(0, layerPath.length)) {
|
||||
next(layerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Validate path breaks on a path separator
|
||||
var c = path[layerPath.length]
|
||||
if (c && c !== '/' && c !== '.') return next(layerError)
|
||||
|
|
|
|||
|
|
@ -186,6 +186,35 @@ describe('app.router', function(){
|
|||
.get('/user/10/edit')
|
||||
.expect('editing user 10', done);
|
||||
})
|
||||
|
||||
it('should ensure regexp matches path prefix', function (done) {
|
||||
var app = express()
|
||||
var p = []
|
||||
|
||||
app.use(/\/api.*/, function (req, res, next) {
|
||||
p.push('a')
|
||||
next()
|
||||
})
|
||||
app.use(/api/, function (req, res, next) {
|
||||
p.push('b')
|
||||
next()
|
||||
})
|
||||
app.use(/\/test/, function (req, res, next) {
|
||||
p.push('c')
|
||||
next()
|
||||
})
|
||||
app.use(function (req, res) {
|
||||
res.end()
|
||||
})
|
||||
|
||||
request(app)
|
||||
.get('/test/api/1234')
|
||||
.expect(200, function (err) {
|
||||
if (err) return done(err)
|
||||
assert.deepEqual(p, ['c'])
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('case sensitivity', function(){
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user