mixu / wildglob

9 stars 1 forks source link

Path mapping from absolute produces invalid path #1

Closed belicekm closed 9 years ago

belicekm commented 9 years ago

When I supply pattern with absolute path the use of path.join inside Glob.prototype._tasks (wildglob\index.js) produces invalid path.

wildglob version 0.0.1 Nodejs v0.12.0 Windows 8.1

I've added some console messages to Glob.prototype._tasks here is the output:

_tasks basenames [ 'C:\\my\\path\\to\\directory/' ]
_tasks patterns C:\my\path\to\directory/**
_tasks self.root C:/
_tasks prefix C:\my\path\to\directory/
_tasks read C:\C:\my\path\to\directory\       <------------ invalid path

The code responsible for such output is inside Glob.prototype._tasks under basenames.map(..):

// 2) the prefix is a path (cannot be empty)
if (isAbsolute(prefix)) {
  // 2a) exprs with absolute paths are mounted at this.root and have no prefix to remove
  read = path.join(self.root, prefix); // this produces invalid path
} else {

My quick naive fix:

// 2) the prefix is a path (cannot be empty)
if (isAbsolute(prefix)) {
  // 2a) exprs with absolute paths are mounted at this.root and have no prefix to remove
  read = path.join(self.root, prefix.replace(/^.:/, '')); // /^.:/ to get rid of the prefix root
} else {
loviselu commented 9 years ago

thx,it work! // 2a) exprs with absolute paths are mounted at this.root and have no prefix to remove if(process.platform === "win32"){ read = path.join(self.root, prefix.replace(/^.:/, '')); }else{ read = path.join(self.root, prefix); }

AaronJan commented 9 years ago

OMG..

I'm just about to making this request, then I found you wrote exactly method than I use.

This issue affected markdown-styles on Windows.

mixu commented 9 years ago

Fixed by #2 - thanks @AaronJan