Compare commits

...

40 Commits

Author SHA1 Message Date
Douglas Christopher Wilson
636a8ae7bc 1.6.4 2015-05-12 21:28:44 -04:00
Douglas Christopher Wilson
320226f35a deps: mime-types@~2.0.11 2015-05-12 21:00:31 -04:00
Douglas Christopher Wilson
2003c3f743 deps: mocha@~2.2.4 2015-05-12 20:59:49 -04:00
Douglas Christopher Wilson
e385089155 deps: debug@~2.2.0 2015-05-12 20:59:15 -04:00
Douglas Christopher Wilson
5462db3946 deps: accepts@~1.2.7 2015-05-12 20:58:24 -04:00
Douglas Christopher Wilson
cb60444cb1 deps: istanbul@0.3.9 2015-05-12 20:57:39 -04:00
Douglas Christopher Wilson
6691f1b75e build: support io.js 2.x 2015-05-12 14:46:31 -04:00
Douglas Christopher Wilson
5cb8bcc448 build: io.js@1.8 2015-05-12 13:14:15 -04:00
Douglas Christopher Wilson
e11f253226 1.6.3 2015-03-14 01:22:30 -04:00
Douglas Christopher Wilson
7381a1d145 Properly escape file names in HTML
fixes #28
2015-03-13 22:34:00 -04:00
Douglas Christopher Wilson
6a4a87edcd build: support io.js 1.x 2015-03-13 22:25:52 -04:00
Douglas Christopher Wilson
99e8ec512a deps: mime-types@~2.0.10 2015-03-13 22:24:20 -04:00
Douglas Christopher Wilson
197d9f6a0f deps: accepts@~1.2.5 2015-03-13 22:23:39 -04:00
Douglas Christopher Wilson
41fe20602a deps: debug@~2.1.3 2015-03-13 21:33:11 -04:00
Douglas Christopher Wilson
b5c886f36d deps: mocha@~2.2.1 2015-03-12 19:03:04 -04:00
Douglas Christopher Wilson
6da896f6d8 deps: istanbul@0.3.7 2015-03-11 22:43:09 -04:00
Douglas Christopher Wilson
5ec9698c08 1.6.2 2015-02-16 22:50:32 -05:00
Douglas Christopher Wilson
4da905e4d3 deps: http-errors@~1.3.1 2015-02-16 19:50:16 -05:00
Douglas Christopher Wilson
62ac6f345b deps: mime-types@~2.0.9 2015-02-16 19:49:09 -05:00
Douglas Christopher Wilson
9afe1a7816 deps: accepts@~1.2.4 2015-02-16 19:48:10 -05:00
Douglas Christopher Wilson
0368c20a58 docs: update badges 2015-02-16 19:46:45 -05:00
Douglas Christopher Wilson
66a13d0814 build: support Node.js 0.12 2015-02-16 19:45:12 -05:00
Douglas Christopher Wilson
b8d8f4524e build: use Travis CI container infrastructure 2015-02-16 19:44:34 -05:00
Douglas Christopher Wilson
75efc2d68e build: use faster AppVeyor Node.js switching 2015-02-16 19:44:04 -05:00
Douglas Christopher Wilson
0bdab07acf 1.6.1 2015-02-01 02:51:12 -05:00
Douglas Christopher Wilson
a6f02f060d build: add AppVeyor 2015-02-01 02:43:24 -05:00
Douglas Christopher Wilson
90252c37b9 deps: accepts@~1.2.3 2015-02-01 02:34:57 -05:00
Douglas Christopher Wilson
94fcb7092e deps: mime-types@~2.0.8 2015-02-01 02:34:03 -05:00
Douglas Christopher Wilson
803e4154b2 1.6.0 2015-01-01 22:15:51 -05:00
Douglas Christopher Wilson
267913151b deps: accepts@~1.2.2 2015-01-01 22:07:12 -05:00
Douglas Christopher Wilson
b1e36ccbf5 deps: batch@0.5.2 2015-01-01 22:05:06 -05:00
Douglas Christopher Wilson
55e914660b deps: mocha@~2.1.0 2015-01-01 21:54:23 -05:00
Douglas Christopher Wilson
0ff43c75a8 deps: mime-types@~2.0.7 2015-01-01 21:53:37 -05:00
Douglas Christopher Wilson
d15b5f1387 deps: debug@~2.1.1 2015-01-01 21:52:27 -05:00
Douglas Christopher Wilson
d5a4b93449 Add link to root directory
closes #23
2014-12-10 23:40:44 -05:00
Douglas Christopher Wilson
244f8a5541 1.5.3 2014-12-10 22:41:49 -05:00
Douglas Christopher Wilson
ed11812d3f deps: http-errors@~1.2.8 2014-12-10 22:40:54 -05:00
Douglas Christopher Wilson
4881fb27da deps: mime-types@~2.0.4 2014-12-10 22:40:20 -05:00
Douglas Christopher Wilson
07e47b1e78 deps: accepts@~1.1.4 2014-12-10 22:39:42 -05:00
Douglas Christopher Wilson
55a5939596 deps: istanbul@0.3.5 2014-12-10 22:38:21 -05:00
11 changed files with 184 additions and 51 deletions

View File

@@ -2,10 +2,10 @@ language: node_js
node_js:
- "0.8"
- "0.10"
- "0.11"
matrix:
allow_failures:
- node_js: "0.11"
fast_finish: true
script: "npm run-script test-travis"
- "0.12"
- "1.0"
- "1.8"
- "2.0"
sudo: false
script: "npm run-script test-ci"
after_script: "npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls"

View File

@@ -1,3 +1,77 @@
1.6.4 / 2015-05-12
==================
* deps: accepts@~1.2.7
- deps: mime-types@~2.0.11
- deps: negotiator@0.5.3
* deps: debug@~2.2.0
- deps: ms@0.7.1
* deps: mime-types@~2.0.11
- Add new mime types
1.6.3 / 2015-03-13
==================
* Properly escape file names in HTML
* deps: accepts@~1.2.5
- deps: mime-types@~2.0.10
* deps: debug@~2.1.3
- Fix high intensity foreground color for bold
- deps: ms@0.7.0
* deps: escape-html@1.0.1
* deps: mime-types@~2.0.10
- Add new mime types
1.6.2 / 2015-02-16
==================
* deps: accepts@~1.2.4
- deps: mime-types@~2.0.9
- deps: negotiator@0.5.1
* deps: http-errors@~1.3.1
- Construct errors using defined constructors from `createError`
- Fix error names that are not identifiers
- Set a meaningful `name` property on constructed errors
* deps: mime-types@~2.0.9
- Add new mime types
- deps: mime-db@~1.7.0
1.6.1 / 2015-01-31
==================
* deps: accepts@~1.2.3
- deps: mime-types@~2.0.8
* deps: mime-types@~2.0.8
- Add new mime types
- deps: mime-db@~1.6.0
1.6.0 / 2015-01-01
==================
* Add link to root directory
* deps: accepts@~1.2.2
- deps: mime-types@~2.0.7
- deps: negotiator@0.5.0
* deps: batch@0.5.2
* deps: debug@~2.1.1
* deps: mime-types@~2.0.7
- Add new mime types
- Fix missing extensions
- Fix various invalid MIME type entries
- Remove example template MIME types
- deps: mime-db@~1.5.0
1.5.3 / 2014-12-10
==================
* deps: accepts@~1.1.4
- deps: mime-types@~2.0.4
* deps: http-errors@~1.2.8
- Fix stack trace from exported function
* deps: mime-types@~2.0.4
- Add new mime types
- deps: mime-db@~1.3.0
1.5.2 / 2014-12-03
==================

View File

@@ -3,7 +3,7 @@
Copyright (c) 2010 Sencha Inc.
Copyright (c) 2011 LearnBoost
Copyright (c) 2011 TJ Holowaychuk
Copyright (c) 2014 Douglas Christopher Wilson
Copyright (c) 2014-2015 Douglas Christopher Wilson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@@ -2,7 +2,8 @@
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Build Status][travis-image]][travis-url]
[![Linux Build][travis-image]][travis-url]
[![Windows Build][appveyor-image]][appveyor-url]
[![Test Coverage][coveralls-image]][coveralls-url]
[![Gratipay][gratipay-image]][gratipay-url]
@@ -115,13 +116,15 @@ app.listen()
[MIT](LICENSE). The [Silk](http://www.famfamfam.com/lab/icons/silk/) icons
are created by/copyright of [FAMFAMFAM](http://www.famfamfam.com/).
[npm-image]: https://img.shields.io/npm/v/serve-index.svg?style=flat
[npm-image]: https://img.shields.io/npm/v/serve-index.svg
[npm-url]: https://npmjs.org/package/serve-index
[travis-image]: https://img.shields.io/travis/expressjs/serve-index.svg?style=flat
[travis-image]: https://img.shields.io/travis/expressjs/serve-index/master.svg?label=linux
[travis-url]: https://travis-ci.org/expressjs/serve-index
[coveralls-image]: https://img.shields.io/coveralls/expressjs/serve-index.svg?style=flat
[appveyor-image]: https://img.shields.io/appveyor/ci/dougwilson/serve-index/master.svg?label=windows
[appveyor-url]: https://ci.appveyor.com/project/dougwilson/serve-index
[coveralls-image]: https://img.shields.io/coveralls/expressjs/serve-index/master.svg
[coveralls-url]: https://coveralls.io/r/expressjs/serve-index?branch=master
[downloads-image]: https://img.shields.io/npm/dm/serve-index.svg?style=flat
[downloads-image]: https://img.shields.io/npm/dm/serve-index.svg
[downloads-url]: https://npmjs.org/package/serve-index
[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg?style=flat
[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg
[gratipay-url]: https://www.gratipay.com/dougwilson/

17
appveyor.yml Normal file
View File

@@ -0,0 +1,17 @@
environment:
matrix:
- nodejs_version: "0.8"
- nodejs_version: "0.10"
- nodejs_version: "0.12"
- nodejs_version: "1.0"
- nodejs_version: "1.8"
- nodejs_version: "2.0"
install:
- ps: Install-Product node $env:nodejs_version
- npm install
build: off
test_script:
- node --version
- npm --version
- npm run test-ci
version: "{build}"

View File

@@ -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
*/
@@ -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
@@ -148,7 +150,7 @@ exports = module.exports = function serveIndex(root, options){
// content-negotiation
var accept = accepts(req);
var type = accept.types(mediaTypes);
var type = accept.type(mediaTypes);
// not acceptable
if (!type) return next(createError(406));
@@ -175,7 +177,7 @@ exports.html = function(req, res, files, next, dir, showUp, icons, path, view, t
str = str
.replace(/\{style\}/g, style.concat(iconStyle(files, icons)))
.replace(/\{files\}/g, html(files, dir, icons, view))
.replace(/\{directory\}/g, dir)
.replace(/\{directory\}/g, escapeHtml(dir))
.replace(/\{linked-path\}/g, htmlPath(dir));
var buf = new Buffer(str, 'utf8');
@@ -227,11 +229,19 @@ function fileSort(a, b) {
*/
function htmlPath(dir) {
var curr = [];
return dir.split('/').map(function(part){
curr.push(encodeURIComponent(part));
return part ? '<a href="' + curr.join('/') + '">' + part + '</a>' : '';
}).join(' / ');
var parts = dir.split('/');
var crumb = new Array(parts.length);
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
if (part) {
parts[i] = encodeURIComponent(part);
crumb[i] = '<a href="' + escapeHtml(parts.slice(0, i + 1).join('/')) + '">' + escapeHtml(part) + '</a>';
}
}
return crumb.join(' / ');
}
/**
@@ -342,7 +352,7 @@ function iconStyle (files, useIcons) {
*/
function html(files, dir, useIcons, view) {
return '<ul id="files" class="view-' + view + '">'
return '<ul id="files" class="view-' + escapeHtml(view) + '">'
+ (view == 'details' ? (
'<li class="header">'
+ '<span class="name">Name</span>'
@@ -382,13 +392,12 @@ 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>'
+ escapeHtml(normalizeSlashes(normalize(path.join('/'))))
+ '" 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>';

View File

@@ -1,22 +1,23 @@
{
"name": "serve-index",
"description": "Serve directory listings",
"version": "1.5.2",
"version": "1.6.4",
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
"license": "MIT",
"repository": "expressjs/serve-index",
"dependencies": {
"accepts": "~1.1.3",
"batch": "0.5.1",
"debug": "~2.1.0",
"http-errors": "~1.2.7",
"mime-types": "~2.0.3",
"accepts": "~1.2.7",
"batch": "0.5.2",
"debug": "~2.2.0",
"escape-html": "1.0.1",
"http-errors": "~1.3.1",
"mime-types": "~2.0.11",
"parseurl": "~1.3.0"
},
"devDependencies": {
"after": "0.8.1",
"istanbul": "0.3.3",
"mocha": "~2.0.1",
"istanbul": "0.3.9",
"mocha": "~2.2.4",
"supertest": "~0.15.0"
},
"files": [
@@ -30,7 +31,7 @@
},
"scripts": {
"test": "mocha --reporter spec --bail --check-leaks test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/"
}
}

View File

@@ -75,7 +75,7 @@
<body class="directory">
<input id="search" type="text" placeholder="Search" autocomplete="off" />
<div id="wrapper">
<h1>{linked-path}</h1>
<h1><a href="/">~</a>{linked-path}</h1>
{files}
</div>
</body>

View File

@@ -109,7 +109,7 @@ describe('serveIndex(root)', function () {
.get('/')
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(/g# %3 o %2525 %37 dir/)
.expect(/g# %3 o & %2525 %37 dir/)
.expect(/users/)
.expect(/file #1\.txt/)
.expect(/nums/)
@@ -128,7 +128,7 @@ describe('serveIndex(root)', function () {
.set('Accept', 'text/html')
.expect(200)
.expect('Content-Type', 'text/html; charset=utf-8')
.expect(/<a href="\/g%23%20%253%20o%20%252525%20%2537%20dir"/)
.expect(/<a href="\/g%23%20%253%20o%20%26%20%252525%20%2537%20dir"/)
.expect(/<a href="\/users"/)
.expect(/<a href="\/file%20%231.txt"/)
.expect(/<a href="\/todo.txt"/)
@@ -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(bodyDoesNotContain('foo & bar'))
.end(done);
});
it('should sort folders first', function (done) {
var server = createServer()
@@ -145,15 +159,16 @@ describe('serveIndex(root)', function () {
.expect(200)
.expect('Content-Type', 'text/html; charset=utf-8')
.end(function (err, res) {
if (err) throw err;
var urls = res.text.split(/<a href="([^"]*)"/).filter(function(s, i){ return i%2; });
if (err) done(err);
var body = res.text.split('</h1>')[1];
var urls = body.split(/<a href="([^"]*)"/).filter(function(s, i){ return i%2; });
assert.deepEqual(urls, [
'/%23directory',
'/collect',
'/g%23%20%253%20o%20%252525%20%2537%20dir',
'/g%23%20%253%20o%20%26%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'
@@ -173,7 +188,7 @@ describe('serveIndex(root)', function () {
.expect(200)
.expect('Content-Type', 'text/plain; charset=utf-8')
.expect(/users/)
.expect(/g# %3 o %2525 %37 dir/)
.expect(/g# %3 o & %2525 %37 dir/)
.expect(/file #1.txt/)
.expect(/todo.txt/)
.expect(/さくら\.txt/)
@@ -453,12 +468,26 @@ describe('serveIndex(root)', function () {
var server = createServer()
request(server)
.get('/g%23%20%253%20o%20%252525%20%2537%20dir/')
.get('/g%23%20%253%20o%20%26%20%252525%20%2537%20dir/')
.set('Accept', 'text/html')
.expect(200)
.expect('Content-Type', 'text/html; charset=utf-8')
.expect(/<a href="\/g%23%20%253%20o%20%252525%20%2537%20dir"/)
.expect(/<a href="\/g%23%20%253%20o%20%252525%20%2537%20dir\/empty.txt"/)
.expect(/<a href="\/g%23%20%253%20o%20%26%20%252525%20%2537%20dir"/)
.expect(/<a href="\/g%23%20%253%20o%20%26%20%252525%20%2537%20dir\/empty.txt"/)
.end(done);
});
it('should property escape directory names', function (done) {
var server = createServer()
request(server)
.get('/g%23%20%253%20o%20%26%20%252525%20%2537%20dir/')
.set('Accept', 'text/html')
.expect(200)
.expect('Content-Type', 'text/html; charset=utf-8')
.expect(/<a href="\/g%23%20%253%20o%20%26%20%252525%20%2537%20dir"/)
.expect(/g# %3 o &amp; %2525 %37 dir/)
.expect(bodyDoesNotContain('g# %3 o & %2525 %37 dir'))
.end(done);
});
@@ -482,7 +511,7 @@ describe('serveIndex(root)', function () {
request(server)
.get('/')
.set('Accept', 'text/html')
.expect(/<a href="\/g%23%20%253%20o%20%252525%20%2537%20dir"/)
.expect(/<a href="\/g%23%20%253%20o%20%26%20%252525%20%2537%20dir"/)
.expect(/<a href="\/users"/)
.expect(/<a href="\/file%20%231.txt"/)
.expect(/<a href="\/todo.txt"/)