11'use strict' ;
22
3- var isglob = require ( 'is-glob' ) ;
3+ var isGlob = require ( 'is-glob' ) ;
44var pathDirname = require ( 'path-dirname' ) ;
55var isWin32 = require ( 'os' ) . platform ( ) === 'win32' ;
66
7+ var slash = '/' ;
8+ var backslash = / \\ / g;
9+ var enclosure = / [ \{ \[ ] .* [ \/ ] * .* [ \} \] ] $ / ;
10+ var globby = / ( ^ | [ ^ \\ ] ) ( [ \{ \[ ] | \( [ ^ \) ] + $ ) / ;
11+ var escaped = / \\ ( [ \* \? \| \[ \] \( \) \{ \} ] ) / g;
12+
713module . exports = function globParent ( str ) {
814 // flip windows path separators
9- if ( isWin32 && str . indexOf ( '/' ) < 0 ) {
10- str = str . split ( '\\' ) . join ( '/' ) ;
15+ if ( isWin32 && str . indexOf ( slash ) < 0 ) {
16+ str = str . replace ( backslash , slash ) ;
1117 }
1218
1319 // special case for strings ending in enclosure containing path separator
14- if ( / [ \{ \[ ] . * [ \/ ] * . * [ \} \] ] $ / . test ( str ) ) {
15- str += '/' ;
20+ if ( enclosure . test ( str ) ) {
21+ str += slash ;
1622 }
1723
1824 // preserves full path in case of trailing path separator
@@ -21,8 +27,8 @@ module.exports = function globParent(str) {
2127 // remove path parts that are globby
2228 do {
2329 str = pathDirname . posix ( str ) ;
24- } while ( isglob ( str ) || / ( ^ | [ ^ \\ ] ) ( [ \{ \[ ] | \( [ ^ \) ] + $ ) / . test ( str ) ) ;
30+ } while ( isGlob ( str ) || globby . test ( str ) ) ;
2531
2632 // remove escape chars and return result
27- return str . replace ( / \\ ( [ \* \? \| \[ \] \( \) \{ \} ] ) / g , '$1' ) ;
33+ return str . replace ( escaped , '$1' ) ;
2834} ;
0 commit comments