11import { expect , test } from 'vitest' ;
2- import { buildFileTree , normalizePath } from './utils' ;
2+ import { buildFileTree , isPathValid , normalizePath } from './utils' ;
33
44test ( 'normalizePath adds a trailing slash and strips leading slashes' , ( ) => {
55 expect ( normalizePath ( '/a/b' ) ) . toBe ( 'a/b/' ) ;
@@ -13,6 +13,23 @@ test('normalizePath returns empty string for root', () => {
1313 expect ( normalizePath ( '/' ) ) . toBe ( '' ) ;
1414} ) ;
1515
16+ test ( 'isPathValid rejects traversal and null bytes' , ( ) => {
17+ expect ( isPathValid ( 'a/../b' ) ) . toBe ( false ) ;
18+ expect ( isPathValid ( 'a/\0b' ) ) . toBe ( false ) ;
19+ } ) ;
20+
21+ test ( 'isPathValid allows normal paths' , ( ) => {
22+ expect ( isPathValid ( 'a/b' ) ) . toBe ( true ) ;
23+ } ) ;
24+
25+ test ( 'isPathValid allows paths with dots' , ( ) => {
26+ expect ( isPathValid ( 'a/b/c.txt' ) ) . toBe ( true ) ;
27+ expect ( isPathValid ( 'a/b/c...' ) ) . toBe ( true ) ;
28+ expect ( isPathValid ( 'a/b/c.../d' ) ) . toBe ( true ) ;
29+ expect ( isPathValid ( 'a/b/..c' ) ) . toBe ( true ) ;
30+ expect ( isPathValid ( 'a/b/[..path]' ) ) . toBe ( true ) ;
31+ } ) ;
32+
1633test ( 'buildFileTree handles a empty flat list' , ( ) => {
1734 const flatList : { type : string , path : string } [ ] = [ ] ;
1835 const tree = buildFileTree ( flatList ) ;
0 commit comments