less.js icon indicating copy to clipboard operation
less.js copied to clipboard

rootpath option prepends absolute system path in Git Bash

Open enepomnyaschih opened this issue 8 years ago • 2 comments

We use shell files to build the application. One step involves less files compilation. It works perfectly in Linux environment, however, in Windows, running these files via Git Bash has unexpected results.

input.less

.a {
	background: url('logo.png');
}

Shell command:

lessc --rootpath=/ input.less output.css

Actual result

.a {
  background: url('C:/Program Files/Git/logo.png');
}

Expected result

.a {
  background: url('/logo.png');
}

The issue can be reproduced only if you run this command in Git Bash. Running it in cmd works fine, however, we don't want to implement a corresponding set of bat files to carry our build process.

enepomnyaschih avatar Jul 24 '18 08:07 enepomnyaschih

Afaik at no point does Less run the passed in --rootpath option through any kind of normalization that would result in the full disk path. Rootpath is just a string path segment that is pre-pended on all paths after they've been rewritten by relative url rewriting.

This is with a high degree of certainty a bug in your own Bash scripts. Bash and by extension Git Bash may auto-expand anything that looks like a file path to its full representation.

In *nix / is just the path /, so things will work fine. In Windows' cmd, / is just a string value /, so things will work fine. But in Git Bash on Windows the / path is expanded to the full location of the root of the virtual environment's file system, located by default at C:\Program Files\Git.

You'll need to escape that / for things to work normally. I.e. your command should be lessc --rootpath=// input.less output.css

rjgotten avatar Jul 27 '18 22:07 rjgotten

You are right, this explains what happens http://www.mingw.org/wiki/Posix_path_conversion

Double slash is not a good solution, because the modified shell scripts won't work in Linux environment anymore. I've decided to rewrite the whole thing in NodeJS using less as a library.

Thank you

enepomnyaschih avatar Jul 28 '18 08:07 enepomnyaschih