Skip to content

Commit

Permalink
fix: remove trailing slashes for fs.open to address Node v23 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Oct 25, 2024
1 parent bfa52bf commit 059bd82
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion st.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ class Mount {

// get a path from a url
getPath (u) {
return path.join(this.path, u)
// trailing slash removal to fix Node.js v23 bug
// https://github.com/nodejs/node/pull/55527
// can be removed when this is resolved and released
return path.join(this.path, u.replace(/\/+$/, ''))
}

// get a url from a path
Expand Down
8 changes: 8 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ test('multiball!', (t) => {
}
})

test('trailing slash', (t) => {
req('/test/test/fixtures/', (er, res, body) => {
t.equal(res.statusCode, 200)
t.ok(/<html>.*Index of \/test\/fixtures<[\s\S]+index\.html[\s\S]+space in filename\.txt[\s\S]+<\/html>/.test(body.toString()))
t.end()
})
})

test('space in filename', (t) => {
req('/test/test/fixtures/space in filename.txt', (er, res, body) => {
t.equal(res.statusCode, 200)
Expand Down

0 comments on commit 059bd82

Please sign in to comment.