Skip to content

Commit

Permalink
Only include the pathname in the 404 message
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Feb 8, 2017
1 parent 1eeee50 commit 4dd6501
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
unreleased
==========

* Only include the pathname in the 404 message
* deps: [email protected]
- Allow colors in workers
- Deprecated `DEBUG_FD` environment variable
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
var debug = require('debug')('finalhandler')
var escapeHtml = require('escape-html')
var onFinished = require('on-finished')
var parseUrl = require('parseurl')
var statuses = require('statuses')
var unpipe = require('unpipe')

Expand Down Expand Up @@ -91,7 +92,7 @@ function finalhandler (req, res, options) {
.replace(DOUBLE_SPACE_REGEXP, '  ') + '\n'
} else {
status = 404
msg = 'Cannot ' + escapeHtml(req.method) + ' ' + escapeHtml(req.originalUrl || req.url) + '\n'
msg = 'Cannot ' + escapeHtml(req.method) + ' ' + escapeHtml(parseUrl.original(req).pathname) + '\n'
}

debug('default %s', status)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"debug": "2.6.0",
"escape-html": "~1.0.3",
"on-finished": "~2.3.0",
"parseurl": "~1.3.1",
"statuses": "~1.3.1",
"unpipe": "~1.0.0"
},
Expand Down
12 changes: 9 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,19 @@ describe('finalhandler(req, res)', function () {
})

describe('404 response', function () {
it('should include method and path', function (done) {
it('should include method and pathname', function (done) {
request(createServer())
.get('/foo')
.expect(404, 'Cannot GET /foo\n', done)
})

it('should escape method and path characters', function (done) {
it('should escape method and pathname characters', function (done) {
rawrequest(createServer())
.get('/<la\'me>')
.expect(404, 'Cannot GET /&lt;la&#39;me&gt;\n', done)
})

it('should include original URL', function (done) {
it('should include original pathname', function (done) {
var server = createServer(function (req, res, next) {
var parts = req.url.split('/')
req.originalUrl = req.url
Expand All @@ -213,6 +213,12 @@ describe('finalhandler(req, res)', function () {
.expect(404, 'Cannot GET /foo/bar\n', done)
})

it('should include pathname only', function (done) {
rawrequest(createServer())
.get('http://localhost/foo?bar=1')
.expect(404, 'Cannot GET /foo\n', done)
})

it('should handle HEAD', function (done) {
request(createServer())
.head('/foo')
Expand Down

0 comments on commit 4dd6501

Please sign in to comment.