Commit 82dad62
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>1 parent 2f01b77 commit 82dad62
2 files changed
Lines changed: 12 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
46 | 57 | | |
47 | 58 | | |
48 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
0 commit comments