@@ -259,6 +259,41 @@ describe('SourceCollector', () => {
259
259
} ) ;
260
260
} ) ;
261
261
262
+ it ( 'should not resolve excessive ../ paths that go beyond root' , ( ) => {
263
+ const files = [
264
+ {
265
+ path : 'packages/parse/src/main.ts' ,
266
+ content : 'import { dec } from "../../../../docs/test.ts";' ,
267
+ } ,
268
+ { path : 'docs/test.ts' , content : 'export const dec = 1;' } ,
269
+ ] ;
270
+
271
+ const result = collector . collect ( 'packages/parse/src/main.ts' , files ) ;
272
+
273
+ // Should only include the entry file, not the incorrectly resolved target
274
+ expect ( result ) . toEqual ( {
275
+ 'packages/parse/src/main.ts' : 'import { dec } from "../../../../docs/test.ts";' ,
276
+ } ) ;
277
+ expect ( result [ 'docs/test.ts' ] ) . toBeUndefined ( ) ;
278
+ } ) ;
279
+
280
+ it ( 'should handle multiple excessive ../ at the beginning' , ( ) => {
281
+ const files = [
282
+ {
283
+ path : 'src/main.ts' ,
284
+ content : 'import { foo } from "../../../../../../../../utils/helper.ts";' ,
285
+ } ,
286
+ { path : 'utils/helper.ts' , content : 'export const foo = 1;' } ,
287
+ ] ;
288
+
289
+ const result = collector . collect ( 'src/main.ts' , files ) ;
290
+
291
+ expect ( result ) . toEqual ( {
292
+ 'src/main.ts' : 'import { foo } from "../../../../../../../../utils/helper.ts";' ,
293
+ } ) ;
294
+ expect ( result [ 'utils/helper.ts' ] ) . toBeUndefined ( ) ;
295
+ } ) ;
296
+
262
297
it ( 'should handle files with only comments' , ( ) => {
263
298
const files = [
264
299
{ path : 'main.ts' , content : '// This is a comment\n/* Block comment */' } ,
0 commit comments