jonkemp / gulp-useref

Parse build blocks in HTML files to replace references to non-optimized scripts or stylesheets.
MIT License
705 stars 93 forks source link

Incorrect join of search paths with file separator and relative file paths #146

Closed estliberitas closed 8 years ago

estliberitas commented 8 years ago

Hello! Recently I found error in gulp-useref@3.0.3 which leads to bad path resolution and unfortunately to plugin error.

Imagine we have alternative paths and one of those paths has file separator:

<!-- build:css({.tmp/serve,src}) styles/vendor.css -->
  <link rel="stylesheet" href="../vendor/some/file.css" />
<!-- endbuild -->

Line 109 of index.js joins HTML file CWD and search paths. So if file.cwd is kind of /a/b/c we'll have following search path:

/a/b/c/{.tmp/serve,src}

Then, we create search pattern for node-glob on line 116. And if we run path.join() for search path and ../vendor/some/file.css, we'll get the following:

/a/b/c/{.tmp/vendor/some/file.css

And this leads to error.

P.S.: OS X, node 4.2.2, npm 2.14.7

estliberitas commented 8 years ago

I added test in referenced PR which proves my point.

estliberitas commented 8 years ago

Update: instead of test-only I sent another PR which attempts to fix the bug.