Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append slash on directories #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,13 @@ function createHtmlFileList(files, dir, useIcons, view) {
var size = file.stat && !isDir
? file.stat.size
: '';

return '<li><a href="'
+ escapeHtml(normalizeSlashes(normalize(path.join('/'))))
+ '" class="' + escapeHtml(classes.join(' ')) + '"'
var href = escapeHtml(normalizeSlashes(normalize(path.join('/'))));
// we want to set trailing slashes on all directories except the root
if (isDir && href !== '/') {
href += '/';
}
return '<li><a href="' + href + '"'
+ ' class="' + escapeHtml(classes.join(' ')) + '"'
+ ' title="' + escapeHtml(file.name) + '">'
+ '<span class="name">' + escapeHtml(file.name) + '</span>'
+ '<span class="size">' + escapeHtml(size) + '</span>'
Expand Down
18 changes: 9 additions & 9 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ 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%26%20%252525%20%2537%20dir"/)
.expect(/<a href="\/users"/)
.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"/)
.expect(/<a href="\/%E3%81%95%E3%81%8F%E3%82%89\.txt"/)
Expand Down Expand Up @@ -163,10 +163,10 @@ describe('serveIndex(root)', function () {
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%26%20%252525%20%2537%20dir',
'/users',
'/%23directory/',
'/collect/',
'/g%23%20%253%20o%20%26%20%252525%20%2537%20dir/',
'/users/',
'/file%20%231.txt',
'/foo%20%26%20bar',
'/nums',
Expand Down Expand Up @@ -315,8 +315,8 @@ describe('serveIndex(root)', function () {
request(server)
.get('/')
.set('Accept', 'text/html')
.expect(/<a href="\/g%23%20%253%20o%20%26%20%252525%20%2537%20dir"/)
.expect(/<a href="\/users"/)
.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"/)
.expect(200, done)
Expand Down Expand Up @@ -602,7 +602,7 @@ describe('serveIndex(root)', function () {
var urls = body.split(/<a href="([^"]*)"/).filter(function(s, i){ return i%2; });
assert.deepEqual(urls, [
'/',
'/users/%23dir',
'/users/%23dir\/',
'/users/index.html',
'/users/tobi.txt'
]);
Expand Down