File tree 2 files changed +25
-2
lines changed
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ var isAbsolute =
14
14
* @returns {boolean } `true` if path is absolute
15
15
*/
16
16
path . isAbsolute = function isAbsolute ( path ) {
17
- return / ^ (?: \/ | \w + : ) / . test ( path ) ;
17
+ return / ^ (?: \/ | \w + : | \\ \\ \w + ) / . test ( path ) ;
18
18
} ;
19
19
20
20
var normalize =
@@ -24,6 +24,13 @@ var normalize =
24
24
* @returns {string } Normalized path
25
25
*/
26
26
path . normalize = function normalize ( path ) {
27
+ var firstTwoCharacters = path . substring ( 0 , 2 ) ;
28
+ var uncPrefix = "" ;
29
+ if ( firstTwoCharacters === "\\\\" ) {
30
+ uncPrefix = firstTwoCharacters ;
31
+ path = path . substring ( 2 ) ;
32
+ }
33
+
27
34
path = path . replace ( / \\ / g, "/" )
28
35
. replace ( / \/ { 2 , } / g, "/" ) ;
29
36
var parts = path . split ( "/" ) ,
@@ -44,7 +51,7 @@ path.normalize = function normalize(path) {
44
51
else
45
52
++ i ;
46
53
}
47
- return prefix + parts . join ( "/" ) ;
54
+ return uncPrefix + prefix + parts . join ( "/" ) ;
48
55
} ;
49
56
50
57
/**
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ tape.test("path", function(test) {
10
10
test . notOk ( path . isAbsolute ( "some\\path\\file.js" ) , "should identify relative windows paths" ) ;
11
11
test . notOk ( path . isAbsolute ( "some/path/file.js" ) , "should identify relative unix paths" ) ;
12
12
13
+ test . ok ( path . isAbsolute ( "\\\\some-unc\\path\\file.js" ) , "should identify windows unc paths" ) ;
14
+
13
15
var paths = [
14
16
{
15
17
actual : "X:\\some\\..\\.\\path\\\\file.js" ,
@@ -45,6 +47,20 @@ tape.test("path", function(test) {
45
47
} , {
46
48
actual : "/.././path//file.js" ,
47
49
normal : "/path/file.js"
50
+ } , {
51
+ actual : "\\\\some-unc\\path\\file.js" ,
52
+ normal : "\\\\some-unc/path/file.js" ,
53
+ resolve : {
54
+ origin : "\\\\some-unc\\path\\origin.js" ,
55
+ expected : "\\\\some-unc/path/file.js"
56
+ }
57
+ } , {
58
+ actual : "\\\\some-unc\\path\\..\\file.js" ,
59
+ normal : "\\\\some-unc/file.js" ,
60
+ resolve : {
61
+ origin : "\\\\some-unc\\path\\..\\origin.js" ,
62
+ expected : "\\\\some-unc/file.js"
63
+ }
48
64
}
49
65
] ;
50
66
You can’t perform that action at this time.
0 commit comments