File tree 2 files changed +35
-2
lines changed
2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -13,8 +13,19 @@ module.exports = function (pattern, options) {
13
13
}
14
14
15
15
return streamfilter ( function ( file , enc , cb ) {
16
- var match = typeof pattern === 'function' ? pattern ( file ) :
17
- multimatch ( path . relative ( file . cwd , file . path ) , pattern , options ) . length > 0 ;
16
+ var match ;
17
+ if ( typeof pattern === 'function' ) {
18
+ match = pattern ( file ) ;
19
+ } else {
20
+ var relPath = path . relative ( file . cwd , file . path ) ;
21
+ // if the path leaves the current working directory, then we need to
22
+ // resolve the absolute path so that the path can be properly matched
23
+ // by minimatch (via multimatch)
24
+ if ( relPath . indexOf ( '../' ) === 0 ) {
25
+ relPath = path . resolve ( relPath ) ;
26
+ }
27
+ match = multimatch ( relPath , pattern , options ) . length > 0 ;
28
+ }
18
29
19
30
cb ( ! match ) ;
20
31
} , {
Original file line number Diff line number Diff line change @@ -160,6 +160,28 @@ describe('filter()', function () {
160
160
161
161
stream . end ( ) ;
162
162
} ) ;
163
+
164
+ it ( 'should filter relative paths that leave current directory tree' , function ( cb ) {
165
+ var stream = filter ( '**/test/**/*.js' ) ;
166
+ var buffer = [ ] ;
167
+ var gfile = path . join ( '..' , '..' , 'test' , 'included.js' ) ;
168
+
169
+ stream . on ( 'data' , function ( file ) {
170
+ buffer . push ( file ) ;
171
+ } ) ;
172
+
173
+ stream . on ( 'end' , function ( ) {
174
+ assert . equal ( buffer . length , 1 ) ;
175
+ assert . equal ( buffer [ 0 ] . relative , gfile ) ;
176
+ cb ( ) ;
177
+ } ) ;
178
+
179
+ stream . write ( new gutil . File ( {
180
+ path : gfile
181
+ } ) ) ;
182
+
183
+ stream . end ( ) ;
184
+ } ) ;
163
185
} ) ;
164
186
165
187
describe ( 'filter.restore' , function ( ) {
You can’t perform that action at this time.
0 commit comments