Skip to content

Commit

Permalink
Use relative paths in directory listing http-party#661
Browse files Browse the repository at this point in the history
  • Loading branch information
boarwell committed Sep 30, 2021
1 parent 29208b7 commit fe2f7b5
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/core/show-dir/index.js
Expand Up @@ -95,7 +95,7 @@ module.exports = (opts) => {
const writeRow = (file) => {
// render a row given a [name, stat] tuple
const isDir = file[1].isDirectory && file[1].isDirectory();
let href = `${parsed.pathname.replace(/\/$/, '')}/${encodeURIComponent(file[0])}`;
let href = `./${encodeURIComponent(file[0])}`;

// append trailing slash and query for dir entry
if (isDir) {
Expand Down
4 changes: 2 additions & 2 deletions test/main.test.js
Expand Up @@ -57,8 +57,8 @@ test('http-server main', (t) => {
requestAsync("http://localhost:8080/").then(res => {
t.ok(res);
t.equal(res.statusCode, 200);
t.includes(res.body, '/file');
t.includes(res.body, '/canYouSeeMe');
t.includes(res.body, './file');
t.includes(res.body, './canYouSeeMe');

// Custom headers
t.equal(res.headers['access-control-allow-origin'], '*');
Expand Down
2 changes: 1 addition & 1 deletion test/showdir-href-encoding.test.js
Expand Up @@ -26,7 +26,7 @@ test('url encoding in href', (t) => {
request.get({
uri,
}, (err, res, body) => {
t.match(body, /href="\/base\/show-dir%24%24href_encoding%24%24\/aname%2Baplus.txt"/, 'We found the right href');
t.match(body, /href="\.\/aname%2Baplus.txt"/, 'We found the right href');
server.close();
t.end();
});
Expand Down
2 changes: 1 addition & 1 deletion test/showdir-search-encoding.test.js
Expand Up @@ -26,7 +26,7 @@ test('directory listing with query string specified', (t) => {
request.get({
uri,
}, (err, res, body) => {
t.match(body, /href="\/base\/subdir\/\?a=1&b=2"/, 'We found the encoded href');
t.match(body, /href="\.\/subdir\/\?a=1&b=2"/, 'We found the encoded href');
t.notMatch(body, /a=1&b=2/, 'We didn\'t find the unencoded query string value');
server.close();
t.end();
Expand Down
2 changes: 1 addition & 1 deletion test/showdir-with-spaces.test.js
Expand Up @@ -26,7 +26,7 @@ test('directory listing when directory name contains spaces', (t) => {
request.get({
uri,
}, (err, res, body) => {
t.ok(/href="\/base\/subdir_with%20space\/index.html"/.test(body), 'We found the right href');
t.ok(/href="\.\/index.html"/.test(body), 'We found the right href');
server.close();
t.end();
});
Expand Down

0 comments on commit fe2f7b5

Please sign in to comment.