@@ -349,4 +349,244 @@ describe('path normalization and utilities', () => {
349349 expect ( pathModule . pathLikeToString ( Buffer . from ( 'test' ) ) ) . toBe ( 'test' )
350350 } )
351351 } )
352+
353+ describe ( 'paths with spaces' , ( ) => {
354+ describe ( 'normalizePath with spaces' , ( ) => {
355+ it ( 'should preserve spaces in Unix paths' , ( ) => {
356+ expect ( normalizePath ( '/path with spaces/to/file' ) ) . toBe (
357+ '/path with spaces/to/file' ,
358+ )
359+ expect ( normalizePath ( 'path with spaces/to/file' ) ) . toBe (
360+ 'path with spaces/to/file' ,
361+ )
362+ } )
363+
364+ it ( 'should preserve spaces in Windows paths' , ( ) => {
365+ expect ( normalizePath ( 'C:\\Program Files\\node\\bin' ) ) . toBe (
366+ 'C:/Program Files/node/bin' ,
367+ )
368+ expect ( normalizePath ( 'path with spaces\\to\\file' ) ) . toBe (
369+ 'path with spaces/to/file' ,
370+ )
371+ } )
372+
373+ it ( 'should normalize complex paths with spaces' , ( ) => {
374+ expect ( normalizePath ( '/my project/src/../lib/file.js' ) ) . toBe (
375+ '/my project/lib/file.js' ,
376+ )
377+ expect ( normalizePath ( './my project/./src/./file.js' ) ) . toBe (
378+ 'my project/src/file.js' ,
379+ )
380+ expect ( normalizePath ( 'C:\\Program Files\\..\\Users\\file' ) ) . toBe (
381+ 'C:/Users/file' ,
382+ )
383+ } )
384+
385+ it ( 'should collapse repeated separators with spaces' , ( ) => {
386+ expect ( normalizePath ( '/path with spaces////to/file' ) ) . toBe (
387+ '/path with spaces/to/file' ,
388+ )
389+ expect ( normalizePath ( 'path with spaces\\\\\\\\to\\\\file' ) ) . toBe (
390+ 'path with spaces/to/file' ,
391+ )
392+ } )
393+
394+ it ( 'should handle relative paths with spaces' , ( ) => {
395+ expect ( normalizePath ( './my project/file.js' ) ) . toBe ( 'my project/file.js' )
396+ expect ( normalizePath ( '../my project/file.js' ) ) . toBe (
397+ '../my project/file.js' ,
398+ )
399+ expect ( normalizePath ( '../../path with spaces/file.js' ) ) . toBe (
400+ '../../path with spaces/file.js' ,
401+ )
402+ } )
403+
404+ it ( 'should handle Buffer with spaces' , ( ) => {
405+ expect ( normalizePath ( Buffer . from ( '/path with spaces/file' ) ) ) . toBe (
406+ '/path with spaces/file' ,
407+ )
408+ } )
409+
410+ it ( 'should handle URL with spaces' , ( ) => {
411+ const url = new URL ( 'file:///path%20with%20spaces/file' )
412+ const result = normalizePath ( url )
413+ expect ( result ) . toContain ( 'path with spaces' )
414+ } )
415+ } )
416+
417+ describe ( 'isPath with spaces' , ( ) => {
418+ it ( 'should identify Unix paths with spaces' , ( ) => {
419+ expect ( isPath ( '/path with spaces/file.js' ) ) . toBe ( true )
420+ expect ( isPath ( './path with spaces/file.js' ) ) . toBe ( true )
421+ expect ( isPath ( '../path with spaces/file.js' ) ) . toBe ( true )
422+ } )
423+
424+ it ( 'should identify Windows paths with spaces' , ( ) => {
425+ expect ( isPath ( 'C:\\Program Files\\node' ) ) . toBe ( true )
426+ expect ( isPath ( 'path with spaces\\to\\file' ) ) . toBe ( true )
427+ } )
428+
429+ it ( 'should identify relative paths with spaces' , ( ) => {
430+ expect ( isPath ( 'my project/src/file.js' ) ) . toBe ( true )
431+ expect ( isPath ( 'folder with spaces/file.js' ) ) . toBe ( true )
432+ } )
433+
434+ it ( 'should handle Buffer with spaces' , ( ) => {
435+ expect ( isPath ( Buffer . from ( '/path with spaces/file' ) ) ) . toBe ( true )
436+ } )
437+
438+ it ( 'should handle URL with spaces' , ( ) => {
439+ expect ( isPath ( new URL ( 'file:///path%20with%20spaces/file' ) ) ) . toBe ( true )
440+ } )
441+ } )
442+
443+ describe ( 'splitPath with spaces' , ( ) => {
444+ it ( 'should split Unix paths with spaces correctly' , ( ) => {
445+ expect ( splitPath ( '/path with spaces/to/file' ) ) . toEqual ( [
446+ '' ,
447+ 'path with spaces' ,
448+ 'to' ,
449+ 'file' ,
450+ ] )
451+ expect ( splitPath ( 'my project/src/index.js' ) ) . toEqual ( [
452+ 'my project' ,
453+ 'src' ,
454+ 'index.js' ,
455+ ] )
456+ } )
457+
458+ it ( 'should split Windows paths with spaces correctly' , ( ) => {
459+ expect ( splitPath ( 'C:\\Program Files\\nodejs' ) ) . toEqual ( [
460+ 'C:' ,
461+ 'Program Files' ,
462+ 'nodejs' ,
463+ ] )
464+ expect ( splitPath ( 'my folder\\sub folder\\file.txt' ) ) . toEqual ( [
465+ 'my folder' ,
466+ 'sub folder' ,
467+ 'file.txt' ,
468+ ] )
469+ } )
470+
471+ it ( 'should handle Buffer with spaces' , ( ) => {
472+ expect ( splitPath ( Buffer . from ( '/path with spaces/file' ) ) ) . toEqual ( [
473+ '' ,
474+ 'path with spaces' ,
475+ 'file' ,
476+ ] )
477+ } )
478+
479+ it ( 'should handle URL with spaces' , ( ) => {
480+ const result = splitPath ( new URL ( 'file:///path%20with%20spaces/file' ) )
481+ expect ( result ) . toContain ( 'path with spaces' )
482+ } )
483+ } )
484+
485+ describe ( 'isNodeModules with spaces' , ( ) => {
486+ it ( 'should detect node_modules in paths with spaces' , ( ) => {
487+ expect ( isNodeModules ( '/my project/node_modules/pkg' ) ) . toBe ( true )
488+ expect ( isNodeModules ( 'C:\\Program Files\\node_modules\\pkg' ) ) . toBe ( true )
489+ } )
490+
491+ it ( 'should reject non-node_modules paths with spaces' , ( ) => {
492+ expect ( isNodeModules ( '/my project/src' ) ) . toBe ( false )
493+ expect ( isNodeModules ( 'C:\\Program Files\\src' ) ) . toBe ( false )
494+ } )
495+
496+ it ( 'should handle Buffer with spaces' , ( ) => {
497+ expect (
498+ isNodeModules ( Buffer . from ( '/path with spaces/node_modules/pkg' ) ) ,
499+ ) . toBe ( true )
500+ } )
501+
502+ it ( 'should handle URL with spaces' , ( ) => {
503+ expect (
504+ isNodeModules (
505+ new URL ( 'file:///path%20with%20spaces/node_modules/pkg' ) ,
506+ ) ,
507+ ) . toBe ( true )
508+ } )
509+ } )
510+
511+ describe ( 'trimLeadingDotSlash with spaces' , ( ) => {
512+ it ( 'should trim ./ from paths with spaces' , ( ) => {
513+ expect ( trimLeadingDotSlash ( './my project/src/file.js' ) ) . toBe (
514+ 'my project/src/file.js' ,
515+ )
516+ expect ( trimLeadingDotSlash ( '.\\path with spaces\\file' ) ) . toBe (
517+ 'path with spaces\\file' ,
518+ )
519+ } )
520+
521+ it ( 'should not trim ../ from paths with spaces' , ( ) => {
522+ expect ( trimLeadingDotSlash ( '../my project/file.js' ) ) . toBe (
523+ '../my project/file.js' ,
524+ )
525+ expect ( trimLeadingDotSlash ( '..\\path with spaces\\file' ) ) . toBe (
526+ '..\\path with spaces\\file' ,
527+ )
528+ } )
529+
530+ it ( 'should handle Buffer with spaces' , ( ) => {
531+ expect ( trimLeadingDotSlash ( Buffer . from ( './path with spaces' ) ) ) . toBe (
532+ 'path with spaces' ,
533+ )
534+ } )
535+ } )
536+
537+ describe ( 'relativeResolve with spaces' , ( ) => {
538+ it ( 'should resolve between paths with spaces' , ( ) => {
539+ const from = '/my project/src'
540+ const to = '/my project/lib'
541+ const result = relativeResolve ( from , to )
542+ expect ( result ) . toBe ( '../lib' )
543+ } )
544+
545+ it ( 'should handle Windows paths with spaces' , ( ) => {
546+ const from = 'C:\\Program Files\\node'
547+ const to = 'C:\\Program Files\\npm'
548+ const result = relativeResolve ( from , to )
549+ expect ( result ) . toBeDefined ( )
550+ expect ( typeof result ) . toBe ( 'string' )
551+ } )
552+
553+ it ( 'should handle parent to child with spaces' , ( ) => {
554+ const from = '/my project/parent'
555+ const to = '/my project/parent/child folder'
556+ const result = relativeResolve ( from , to )
557+ expect ( result ) . toBe ( 'child folder' )
558+ } )
559+
560+ it ( 'should handle child to parent with spaces' , ( ) => {
561+ const from = '/my project/child folder'
562+ const to = '/my project'
563+ const result = relativeResolve ( from , to )
564+ expect ( result ) . toBe ( '..' )
565+ } )
566+ } )
567+
568+ describe ( 'isRelative with spaces' , ( ) => {
569+ it ( 'should identify relative paths with spaces' , ( ) => {
570+ expect ( isRelative ( 'my project/src' ) ) . toBe ( true )
571+ expect ( isRelative ( './path with spaces' ) ) . toBe ( true )
572+ expect ( isRelative ( '../folder with spaces' ) ) . toBe ( true )
573+ } )
574+
575+ it ( 'should identify absolute paths with spaces' , ( ) => {
576+ expect ( isRelative ( '/path with spaces' ) ) . toBe ( false )
577+ if ( process . platform === 'win32' ) {
578+ expect ( isRelative ( 'C:\\Program Files' ) ) . toBe ( false )
579+ }
580+ } )
581+
582+ it ( 'should handle Buffer with spaces' , ( ) => {
583+ expect ( isRelative ( Buffer . from ( './path with spaces' ) ) ) . toBe ( true )
584+ expect ( isRelative ( Buffer . from ( '/path with spaces' ) ) ) . toBe ( false )
585+ } )
586+
587+ it ( 'should handle URL with spaces' , ( ) => {
588+ expect ( isRelative ( new URL ( 'file:///path%20with%20spaces' ) ) ) . toBe ( false )
589+ } )
590+ } )
591+ } )
352592} )
0 commit comments