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

Use relative paths in directory listing #661 #732

Merged
merged 1 commit into from Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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