borodean / postcss-assets

An asset manager for PostCSS
MIT License
537 stars 32 forks source link

Windows problem: backslashes returned for css output #19

Closed aproc closed 9 years ago

aproc commented 9 years ago

I'm on a Windows machine and using postcss-assets. When I use resolve() in combination with the 'relativeTo' option, I receive double backslashes as css output instead of a simple /

/* source input: */
.selector { background-image: resolve('filename.png'); }
/* generated output: */
.selector { background-image: url('..\\images\\filename.png'); }
/* expected output: */
.selector { background-image: url('../images/filename.png'); }
borodean commented 9 years ago

Hi @aproc! Thanks for your feedback. I think I can fix it.

The only question is how to make it testable—Travis CI has no option for running tests on Windows.

aproc commented 9 years ago

Sorry, I'm not familar with Travis CI. I had a look at your code and tried a quick and dirty way to get the expected result after inspecting the output of cssesc(url.format(assetUrl)). But I'm not sure if it has any unwanted side effects. Maybe it helps?

/* index.js */
Assets.prototype.resolveUrl = function (assetStr) {
...
  /* line: 130 */
  return cssesc(url.format(assetUrl));

  /* change works on windows */
  return cssesc(url.format(assetUrl.path));
}
borodean commented 9 years ago

Fixed in 2.1.1.