Skip to content

Commit 7b7b9f7

Browse files
committed
use escape-html for escaping
1 parent 36a6af9 commit 7b7b9f7

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

History.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
unreleased
2+
==========
3+
4+
* use `escape-html` for escaping
5+
16
1.2.0 / 2014-05-29
27
==================
38

index.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Module dependencies.
1111
*/
1212

13+
var escapeHtml = require('escape-html');
1314
var parseurl = require('parseurl');
1415
var resolve = require('path').resolve;
1516
var send = require('send');
@@ -79,7 +80,7 @@ exports = module.exports = function(root, options){
7980
target = url.format(originalUrl);
8081
res.statusCode = 303;
8182
res.setHeader('Location', target);
82-
res.end('Redirecting to ' + escape(target));
83+
res.end('Redirecting to ' + escapeHtml(target));
8384
}
8485

8586
function error(err) {
@@ -103,22 +104,6 @@ exports = module.exports = function(root, options){
103104

104105
exports.mime = send.mime;
105106

106-
/**
107-
* Escape the given string of `html`.
108-
*
109-
* @param {String} html
110-
* @return {String}
111-
* @api private
112-
*/
113-
114-
function escape(html) {
115-
return String(html)
116-
.replace(/&(?!\w+;)/g, '&')
117-
.replace(/</g, '&lt;')
118-
.replace(/>/g, '&gt;')
119-
.replace(/"/g, '&quot;');
120-
};
121-
122107
/**
123108
* Shallow clone a single object.
124109
*

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"url": "https://github.com/expressjs/serve-static/issues"
1313
},
1414
"dependencies": {
15+
"escape-html": "1.0.1",
1516
"parseurl": "1.0.1",
1617
"send": "0.4.0"
1718
},

0 commit comments

Comments
 (0)