Skip to content

Commit 693ad87

Browse files
authored
Merge pull request #732 from boarwell/relative-paths
Use relative paths in directory listing #661
2 parents 29208b7 + fe2f7b5 commit 693ad87

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

lib/core/show-dir/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ module.exports = (opts) => {
9595
const writeRow = (file) => {
9696
// render a row given a [name, stat] tuple
9797
const isDir = file[1].isDirectory && file[1].isDirectory();
98-
let href = `${parsed.pathname.replace(/\/$/, '')}/${encodeURIComponent(file[0])}`;
98+
let href = `./${encodeURIComponent(file[0])}`;
9999

100100
// append trailing slash and query for dir entry
101101
if (isDir) {

test/main.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ test('http-server main', (t) => {
5757
requestAsync("http://localhost:8080/").then(res => {
5858
t.ok(res);
5959
t.equal(res.statusCode, 200);
60-
t.includes(res.body, '/file');
61-
t.includes(res.body, '/canYouSeeMe');
60+
t.includes(res.body, './file');
61+
t.includes(res.body, './canYouSeeMe');
6262

6363
// Custom headers
6464
t.equal(res.headers['access-control-allow-origin'], '*');

test/showdir-href-encoding.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test('url encoding in href', (t) => {
2626
request.get({
2727
uri,
2828
}, (err, res, body) => {
29-
t.match(body, /href="\/base\/show-dir%24%24href_encoding%24%24\/aname%2Baplus.txt"/, 'We found the right href');
29+
t.match(body, /href="\.\/aname%2Baplus.txt"/, 'We found the right href');
3030
server.close();
3131
t.end();
3232
});

test/showdir-search-encoding.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test('directory listing with query string specified', (t) => {
2626
request.get({
2727
uri,
2828
}, (err, res, body) => {
29-
t.match(body, /href="\/base\/subdir\/\?a=1&b=2"/, 'We found the encoded href');
29+
t.match(body, /href="\.\/subdir\/\?a=1&b=2"/, 'We found the encoded href');
3030
t.notMatch(body, /a=1&b=2/, 'We didn\'t find the unencoded query string value');
3131
server.close();
3232
t.end();

test/showdir-with-spaces.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test('directory listing when directory name contains spaces', (t) => {
2626
request.get({
2727
uri,
2828
}, (err, res, body) => {
29-
t.ok(/href="\/base\/subdir_with%20space\/index.html"/.test(body), 'We found the right href');
29+
t.ok(/href="\.\/index.html"/.test(body), 'We found the right href');
3030
server.close();
3131
t.end();
3232
});

0 commit comments

Comments
 (0)