SIGN IN SIGN UP
honojs / hono UNCLAIMED

Web framework built on Web Standards

0 0 77 TypeScript

fix(serve-static): normalize all backslashes in file paths, not just the first (#4962)

`getFilePathWithoutDefaultDocument` converts backslash separators to slashes so
the same path resolves consistently regardless of the separator style of the
incoming request. The replace used a non-global regex (`/\/`), so only the
FIRST backslash was converted: a path with multiple segments like
`foo\bar\baz.txt` became `foo/bar\baz.txt` — mixed separators that resolve to the
wrong file (or 404) on platforms that don't treat `\` as a separator. The
adjacent comment (`foo\bar.txt => foo/bar.txt`) shows the intent was to
normalize all of them.

Fix: add the `g` flag (`/\/g`). Behaviour is unchanged for any path with zero
or one backslash, so all existing tests pass; added a regression test covering a
multi-segment path (with and without `root`) that returns the broken
`foo/bar\baz.txt` before this change.

tsc --noEmit clean; eslint + prettier clean.

Co-authored-by: Prodia Evolution Worker <evo@prodia.dev>
F
francisjohnjohnston-web committed
82dad6297c90c33c41bf48b4530509a21588ad06
Parent: 2f01b77
Committed by GitHub <noreply@github.com> on 5/24/2026, 8:42:00 AM