@@ -32,10 +32,10 @@ function assertPath(path) {
32
32
// Resolves . and .. elements in a path with directory names
33
33
function normalizeStringWin32 ( path , allowAboveRoot ) {
34
34
var res = '' ;
35
+ var lastSegmentLength = 0 ;
35
36
var lastSlash = - 1 ;
36
37
var dots = 0 ;
37
38
var code ;
38
- var isAboveRoot = false ;
39
39
for ( var i = 0 ; i <= path . length ; ++ i ) {
40
40
if ( i < path . length )
41
41
code = path . charCodeAt ( i ) ;
@@ -47,7 +47,7 @@ function normalizeStringWin32(path, allowAboveRoot) {
47
47
if ( lastSlash === i - 1 || dots === 1 ) {
48
48
// NOOP
49
49
} else if ( lastSlash !== i - 1 && dots === 2 ) {
50
- if ( res . length < 2 || ! isAboveRoot ||
50
+ if ( res . length < 2 || lastSegmentLength !== 2 ||
51
51
res . charCodeAt ( res . length - 1 ) !== 46 /*.*/ ||
52
52
res . charCodeAt ( res . length - 2 ) !== 46 /*.*/ ) {
53
53
if ( res . length > 2 ) {
@@ -58,20 +58,22 @@ function normalizeStringWin32(path, allowAboveRoot) {
58
58
break ;
59
59
}
60
60
if ( j !== start ) {
61
- if ( j === - 1 )
61
+ if ( j === - 1 ) {
62
62
res = '' ;
63
- else
63
+ lastSegmentLength = 0 ;
64
+ } else {
64
65
res = res . slice ( 0 , j ) ;
66
+ lastSegmentLength = j ;
67
+ }
65
68
lastSlash = i ;
66
69
dots = 0 ;
67
- isAboveRoot = false ;
68
70
continue ;
69
71
}
70
72
} else if ( res . length === 2 || res . length === 1 ) {
71
73
res = '' ;
74
+ lastSegmentLength = 0 ;
72
75
lastSlash = i ;
73
76
dots = 0 ;
74
- isAboveRoot = false ;
75
77
continue ;
76
78
}
77
79
}
@@ -80,14 +82,14 @@ function normalizeStringWin32(path, allowAboveRoot) {
80
82
res += '\\..' ;
81
83
else
82
84
res = '..' ;
83
- isAboveRoot = true ;
85
+ lastSegmentLength = 2 ;
84
86
}
85
87
} else {
86
88
if ( res . length > 0 )
87
89
res += '\\' + path . slice ( lastSlash + 1 , i ) ;
88
90
else
89
91
res = path . slice ( lastSlash + 1 , i ) ;
90
- isAboveRoot = false ;
92
+ lastSegmentLength = i - lastSlash - 1 ;
91
93
}
92
94
lastSlash = i ;
93
95
dots = 0 ;
@@ -103,10 +105,10 @@ function normalizeStringWin32(path, allowAboveRoot) {
103
105
// Resolves . and .. elements in a path with directory names
104
106
function normalizeStringPosix ( path , allowAboveRoot ) {
105
107
var res = '' ;
108
+ var lastSegmentLength = 0 ;
106
109
var lastSlash = - 1 ;
107
110
var dots = 0 ;
108
111
var code ;
109
- var isAboveRoot = false ;
110
112
for ( var i = 0 ; i <= path . length ; ++ i ) {
111
113
if ( i < path . length )
112
114
code = path . charCodeAt ( i ) ;
@@ -118,7 +120,7 @@ function normalizeStringPosix(path, allowAboveRoot) {
118
120
if ( lastSlash === i - 1 || dots === 1 ) {
119
121
// NOOP
120
122
} else if ( lastSlash !== i - 1 && dots === 2 ) {
121
- if ( res . length < 2 || ! isAboveRoot ||
123
+ if ( res . length < 2 || lastSegmentLength !== 2 ||
122
124
res . charCodeAt ( res . length - 1 ) !== 46 /*.*/ ||
123
125
res . charCodeAt ( res . length - 2 ) !== 46 /*.*/ ) {
124
126
if ( res . length > 2 ) {
@@ -129,20 +131,22 @@ function normalizeStringPosix(path, allowAboveRoot) {
129
131
break ;
130
132
}
131
133
if ( j !== start ) {
132
- if ( j === - 1 )
134
+ if ( j === - 1 ) {
133
135
res = '' ;
134
- else
136
+ lastSegmentLength = 0 ;
137
+ } else {
135
138
res = res . slice ( 0 , j ) ;
139
+ lastSegmentLength = j ;
140
+ }
136
141
lastSlash = i ;
137
142
dots = 0 ;
138
- isAboveRoot = false ;
139
143
continue ;
140
144
}
141
145
} else if ( res . length === 2 || res . length === 1 ) {
142
146
res = '' ;
147
+ lastSegmentLength = 0 ;
143
148
lastSlash = i ;
144
149
dots = 0 ;
145
- isAboveRoot = false ;
146
150
continue ;
147
151
}
148
152
}
@@ -151,14 +155,14 @@ function normalizeStringPosix(path, allowAboveRoot) {
151
155
res += '/..' ;
152
156
else
153
157
res = '..' ;
154
- isAboveRoot = true ;
158
+ lastSegmentLength = 2 ;
155
159
}
156
160
} else {
157
161
if ( res . length > 0 )
158
162
res += '/' + path . slice ( lastSlash + 1 , i ) ;
159
163
else
160
164
res = path . slice ( lastSlash + 1 , i ) ;
161
- isAboveRoot = false ;
165
+ lastSegmentLength = i - lastSlash - 1 ;
162
166
}
163
167
lastSlash = i ;
164
168
dots = 0 ;
0 commit comments