Skip to content

Commit

Permalink
Property escape file names in HTML
Browse files Browse the repository at this point in the history
fixes #28
  • Loading branch information
dougwilson committed Mar 14, 2015
1 parent 41fe206 commit 0d135e7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
unreleased
==========

* Property escape file names in HTML
* deps: debug@~2.1.3
- Fix high intensity foreground color for bold
- deps: ms@0.7.0
* deps: escape-html@1.0.1

1.6.2 / 2015-02-16
==================
Expand Down
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* serve-index
* Copyright(c) 2011 Sencha Inc.
* Copyright(c) 2011 TJ Holowaychuk
* Copyright(c) 2014 Douglas Christopher Wilson
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/

Expand All @@ -11,11 +11,13 @@

/**
* Module dependencies.
* @private
*/

var accepts = require('accepts');
var createError = require('http-errors');
var debug = require('debug')('serve-index');
var escapeHtml = require('escape-html');
var fs = require('fs')
, path = require('path')
, normalize = path.normalize
Expand Down Expand Up @@ -383,12 +385,11 @@ function html(files, dir, useIcons, view) {

return '<li><a href="'
+ normalizeSlashes(normalize(path.join('/')))
+ '" class="'
+ classes.join(' ') + '"'
+ ' title="' + file.name + '">'
+ '<span class="name">'+file.name+'</span>'
+ '<span class="size">'+size+'</span>'
+ '<span class="date">'+date+'</span>'
+ '" class="' + escapeHtml(classes.join(' ')) + '"'
+ ' title="' + escapeHtml(file.name) + '">'
+ '<span class="name">' + escapeHtml(file.name) + '</span>'
+ '<span class="size">' + escapeHtml(size) + '</span>'
+ '<span class="date">' + escapeHtml(date) + '</span>'
+ '</a></li>';

}).join('\n') + '</ul>';
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 @@
"accepts": "~1.2.4",
"batch": "0.5.2",
"debug": "~2.1.3",
"escape-html": "1.0.1",
"http-errors": "~1.3.1",
"mime-types": "~2.0.9",
"parseurl": "~1.3.0"
Expand Down
File renamed without changes.
16 changes: 15 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ describe('serveIndex(root)', function () {
.end(done);
});

it('should property escape file names', function (done) {
var server = createServer()

request(server)
.get('/')
.set('Accept', 'text/html')
.expect(200)
.expect('Content-Type', 'text/html; charset=utf-8')
.expect(/<a href="\/foo%20%26%20bar"/)
.expect(/foo &amp; bar/)
.expect(/foo &(?! )/)
.end(done);
});

it('should sort folders first', function (done) {
var server = createServer()

Expand All @@ -154,7 +168,7 @@ describe('serveIndex(root)', function () {
'/g%23%20%253%20o%20%252525%20%2537%20dir',
'/users',
'/file%20%231.txt',
'/foo%20bar',
'/foo%20%26%20bar',
'/nums',
'/todo.txt',
'/%E3%81%95%E3%81%8F%E3%82%89.txt'
Expand Down

0 comments on commit 0d135e7

Please sign in to comment.