Skip to content

Commit e7cbc4c

Browse files
committed
Fix data-uri relative url to be relative in the same way as normal url's
1 parent f68337e commit e7cbc4c

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

lib/less/env.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
'dumpLineNumbers', // option - whether to dump line numbers
1313
'compress', // option - whether to compress
1414
'mime', // browser only - mime type for sheet import
15-
'entryPath', // browser only, path of entry less file
16-
'rootFilename' // browser only, href of the entry less file
15+
'entryPath', // browser only - path of entry less file
16+
'rootFilename', // browser only - href of the entry less file
17+
'currentDirectory' // node only - the current directory
1718
];
1819

1920
tree.parseEnv = function(options) {

lib/less/functions.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,8 @@ tree.functions = {
390390
filePath = mimetype;
391391
}
392392

393-
if (this.relativePath && this.env.isPathRelative(filePath)) {
394-
filePath = path.join(this.relativePath, filePath);
393+
if (this.currentDirectory && this.env.isPathRelative(filePath)) {
394+
filePath = path.join(this.currentDirectory, filePath);
395395
}
396396

397397
// detect the mimetype if not given
@@ -497,10 +497,10 @@ function clamp(val) {
497497
return Math.min(1, Math.max(0, val));
498498
}
499499

500-
tree.functionCall = function(env, rootpath, relativePath) {
500+
tree.functionCall = function(env, rootpath, currentDirectory) {
501501
this.env = env;
502502
this.rootpath = rootpath;
503-
this.relativePath = relativePath;
503+
this.currentDirectory = currentDirectory;
504504
};
505505

506506
tree.functionCall.prototype = tree.functions;

lib/less/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ less.Parser.importer = function (file, paths, callback, env) {
124124
if(env.relativeUrls && !/^(?:[a-z-]+:|\/)/.test(file) && j != -1) {
125125
env.rootpath = env.rootpath + file.slice(0, j+1); // append (sub|sup) directory path of imported file
126126
}
127+
if (env.relativeUrls) {
128+
env.currentDirectory = pathname.replace(/[^\\\/]*$/, "");
129+
}
127130

128131
env.contents[pathname] = data; // Updating top importing parser content cache.
129132
env.paths = [dirname].concat(paths);

lib/less/parser.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ less.Parser = function Parser(env) {
7171
env = new tree.parseEnv(env);
7272
}
7373

74+
if (!env.currentDirectory && env.filename) {
75+
// only works for node, only used for node
76+
env.currentDirectory = env.filename.replace(/[^\/\\]*$/, "");
77+
}
78+
7479
// This function is called after all files
7580
// have been imported through `@import`.
7681
var finish = function () {};
@@ -630,7 +635,7 @@ less.Parser = function Parser(env) {
630635
return;
631636
}
632637

633-
if (name) { return new(tree.Call)(name, args, index, env.filename, env.rootpath, env.rootpath || env.paths[0]); }
638+
if (name) { return new(tree.Call)(name, args, index, env.filename, env.rootpath, env.currentDirectory); }
634639
},
635640
arguments: function () {
636641
var args = [], arg;

lib/less/tree/call.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
//
44
// A function call node.
55
//
6-
tree.Call = function (name, args, index, filename, rootpath, relativePath) {
6+
tree.Call = function (name, args, index, filename, rootpath, currentDirectory) {
77
this.name = name;
88
this.args = args;
99
this.index = index;
1010
this.filename = filename;
1111
this.rootpath = rootpath;
12-
this.relativePath = relativePath;
12+
this.currentDirectory = currentDirectory;
1313
};
1414
tree.Call.prototype = {
1515
//
@@ -32,7 +32,7 @@ tree.Call.prototype = {
3232

3333
if (nameLC in tree.functions) { // 1.
3434
try {
35-
func = new tree.functionCall(env, this.rootpath, this.relativePath);
35+
func = new tree.functionCall(env, this.rootpath, this.currentDirectory);
3636
result = func[nameLC].apply(func, args);
3737
if (result != null) {
3838
return result;

0 commit comments

Comments
 (0)