diff --git a/bower.json b/bower.json new file mode 100644 index 00000000..e6f0686c --- /dev/null +++ b/bower.json @@ -0,0 +1,5 @@ +{ + "name": "less", + "version": "1.4.2", + "main": ["./lib/less/index"] +} diff --git a/lib/less/env.js b/lib/less/env.js index dd4d5a5f..595a54f9 100644 --- a/lib/less/env.js +++ b/lib/less/env.js @@ -87,6 +87,33 @@ return !/^(?:[a-z-]+:|\/)/.test(path); }; + tree.evalEnv.prototype.normalizePath = function( path ) { + var + segments = path.split("/").reverse(), + segment; + + path = []; + while (segments.length !== 0 ) { + segment = segments.pop(); + switch( segment ) { + case ".": + break; + case "..": + if ((path.length === 0) || (path[path.length - 1] === "..")) { + path.push( segment ); + } else { + path.pop(); + } + break; + default: + path.push( segment ); + break; + } + } + + return path.join("/"); + }; + //todo - do the same for the toCSS env //tree.toCSSEnv = function (options) { //}; diff --git a/lib/less/tree/import.js b/lib/less/tree/import.js index e4cfd9e2..a2ab3d76 100644 --- a/lib/less/tree/import.js +++ b/lib/less/tree/import.js @@ -73,13 +73,18 @@ tree.Import.prototype = { evalPath: function (env) { var path = this.path.eval(env); var rootpath = this.currentFileInfo && this.currentFileInfo.rootpath; - if (rootpath && !(path instanceof tree.URL)) { - var pathValue = path.value; - // Add the base path if the import is relative - if (pathValue && env.isPathRelative(pathValue)) { - path.value = rootpath + pathValue; + + if (!(path instanceof tree.URL)) { + if (rootpath) { + var pathValue = path.value; + // Add the base path if the import is relative + if (pathValue && env.isPathRelative(pathValue)) { + path.value = rootpath + pathValue; + } } + path.value = env.normalizePath(path.value); } + return path; }, eval: function (env) { diff --git a/lib/less/tree/url.js b/lib/less/tree/url.js index 7ba562fa..79c2879c 100644 --- a/lib/less/tree/url.js +++ b/lib/less/tree/url.js @@ -27,6 +27,8 @@ tree.URL.prototype = { val.value = rootpath + val.value; } + val.value = ctx.normalizePath(val.value); + return new(tree.URL)(val, null); } }; diff --git a/test/css/static-urls/urls.css b/test/css/static-urls/urls.css index 565ccb44..95f04fbb 100644 --- a/test/css/static-urls/urls.css +++ b/test/css/static-urls/urls.css @@ -1,4 +1,4 @@ -@import "folder (1)/../css/background.css"; +@import "css/background.css"; @import "folder (1)/import-test-d.css"; @font-face { src: url("/fonts/garamond-pro.ttf"); @@ -30,11 +30,11 @@ #logo { width: 100px; height: 100px; - background: url('folder (1)/../assets/logo.png'); + background: url('assets/logo.png'); } @font-face { font-family: xecret; - src: url('folder (1)/../assets/xecret.ttf'); + src: url('assets/xecret.ttf'); } #secret { font-family: xecret, sans-serif; diff --git a/test/css/urls.css b/test/css/urls.css index ef812605..a0618689 100644 --- a/test/css/urls.css +++ b/test/css/urls.css @@ -1,4 +1,4 @@ -@import "import/../css/background.css"; +@import "css/background.css"; @import "import/import-test-d.css"; @import "file.css"; @font-face { @@ -33,11 +33,11 @@ #logo { width: 100px; height: 100px; - background: url('import/imports/../assets/logo.png'); + background: url('import/assets/logo.png'); } @font-face { font-family: xecret; - src: url('import/imports/../assets/xecret.ttf'); + src: url('import/assets/xecret.ttf'); } #secret { font-family: xecret, sans-serif;