Fix fatal panic on non-absolute path in VFS#4248
Conversation
Instead of panicking when a non-absolute path reaches VFS operations,
RootLength now returns 0, SplitPath returns empty strings, and
RootAndPath returns nil fsys. This causes FileExists/DirectoryExists
to return false and ReadFile to return ("", false) for non-absolute paths,
matching TypeScript's behavior where sys.fileExists simply returns false.
Fixes #1291
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
|
@copilot you did not add a test |
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
|
@copilot can you investigate adding a real world example as a compiler or fourslash test that fails without any fix? |
I investigated compiler and fourslash coverage paths. Standard compiler tests normalize |
The VFS layer panics when a non-absolute path reaches
RootLength()via the module resolution pipeline. This can occur whencontainingDirectoryis empty, causingnormalizePathForCJSResolution("", "./foo")to produce a relative path that propagates throughFileExists→Stat→RootAndPath→SplitPath→RootLength.TypeScript's
sys.fileExistssimply returnsfalsefor such paths. The Go port's defensivepanicis too strict.Changes
RootLengthreturns0instead of panicking for non-absolute pathsSplitPathreturns("", "")when root length is zeroRootAndPathreturnsnilfsys when rootName is empty, causing downstreamFileExists/DirectoryExiststo returnfalseandReadFileto return("", false)false/empty return