diff --git a/Gruntfile.js b/Gruntfile.js
index dd6b8a931..c90ab2b48 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -70,14 +70,18 @@ module.exports = function (grunt) {
var sauceJobs = {};
- var browserTests = [ 'filemanager-plugin',
+
+ var browserTests = [
+ 'filemanager-plugin',
'visitor-plugin',
'global-vars',
'modify-vars',
'production',
'rootpath-relative',
+ 'rootpath-rewrite-urls',
'rootpath',
'relative-urls',
+ 'rewrite-urls',
'browser',
'no-js-errors',
'legacy'
@@ -358,6 +362,14 @@ module.exports = function (grunt) {
outfile: 'tmp/browser/test-runner-relative-urls.html'
}
},
+ rewriteUrls: {
+ src: ['test/browser/less/rewrite-urls/*.less'],
+ options: {
+ helpers: 'test/browser/runner-rewrite-urls-options.js',
+ specs: 'test/browser/runner-rewrite-urls-spec.js',
+ outfile: 'tmp/browser/test-runner-rewrite-urls.html'
+ }
+ },
rootpath: {
src: ['test/browser/less/rootpath/*.less'],
options: {
@@ -374,6 +386,14 @@ module.exports = function (grunt) {
outfile: 'tmp/browser/test-runner-rootpath-relative.html'
}
},
+ rootpathRewriteUrls: {
+ src: ['test/browser/less/rootpath-rewrite-urls/*.less'],
+ options: {
+ helpers: 'test/browser/runner-rootpath-rewrite-urls-options.js',
+ specs: 'test/browser/runner-rootpath-rewrite-urls-spec.js',
+ outfile: 'tmp/browser/test-runner-rootpath-rewrite-urls.html'
+ }
+ },
production: {
src: ['test/browser/less/production/*.less'],
options: {
diff --git a/bin/lessc b/bin/lessc
index 7360ff07e..121e36209 100755
--- a/bin/lessc
+++ b/bin/lessc
@@ -475,9 +475,23 @@ function processPluginQueue() {
options.rootpath = match[2].replace(/\\/g, '/');
}
break;
- case 'ru':
case 'relative-urls':
- options.relativeUrls = true;
+ console.warn('The relative-urls option has been replaced by the rewrite-urls option and will be removed.');
+ options.rewriteUrls = 'all';
+ break;
+ case 'ru':
+ case 'rewrite-urls':
+ if (match[2] === 'all' || match[2] === 'local') {
+ options.rewriteUrls = match[2];
+ } else if (match[2] === 'off') {
+ options.rewriteUrls = false;
+ } else if (!match[2]) {
+ options.rewriteUrls = 'all';
+ } else {
+ console.error('Unknown rewrite-urls argument ' + match[2]);
+ continueProcessing = false;
+ process.exitCode = 1;
+ }
break;
case 'sm':
case 'strict-math':
diff --git a/build.gradle b/build.gradle
index b626b5dd3..181a55f29 100644
--- a/build.gradle
+++ b/build.gradle
@@ -52,7 +52,7 @@ task testRhino(type: AllRhinoTests) {
}
task testRhinoBase(type: RhinoTest) {
- options = [ '--strict-math=true', '--relative-urls' ]
+ options = [ '--strict-math=true', '--rewrite-urls' ]
}
task testRhinoDebugAll(type: DebugRhinoTest) {
diff --git a/lib/less-browser/index.js b/lib/less-browser/index.js
index dd0bc361a..86362023e 100644
--- a/lib/less-browser/index.js
+++ b/lib/less-browser/index.js
@@ -26,6 +26,10 @@ module.exports = function(window, options) {
if (options.functions) {
less.functions.functionRegistry.addMultiple(options.functions);
}
+ // Ensure compatibility with deprecated relativeUrls options
+ if (options.relativeUrls) {
+ options.rewriteUrls = 'all';
+ }
var typePattern = /^text\/(x-)?less$/;
@@ -93,7 +97,8 @@ module.exports = function(window, options) {
currentDirectory: fileManager.getPath(path),
filename: path,
rootFilename: path,
- relativeUrls: instanceOptions.relativeUrls};
+ rewriteUrls: instanceOptions.rewriteUrls
+ };
newFileInfo.entryPath = newFileInfo.currentDirectory;
newFileInfo.rootpath = instanceOptions.rootpath || newFileInfo.currentDirectory;
diff --git a/lib/less-node/image-size.js b/lib/less-node/image-size.js
index ef8c84878..f80a4546b 100644
--- a/lib/less-node/image-size.js
+++ b/lib/less-node/image-size.js
@@ -6,7 +6,7 @@ module.exports = function(environment) {
function imageSize(functionContext, filePathNode) {
var filePath = filePathNode.value;
var currentFileInfo = functionContext.currentFileInfo;
- var currentDirectory = currentFileInfo.relativeUrls ?
+ var currentDirectory = currentFileInfo.rewriteUrls ?
currentFileInfo.currentDirectory : currentFileInfo.entryPath;
var fragmentStart = filePath.indexOf('#');
diff --git a/lib/less-node/lessc-helper.js b/lib/less-node/lessc-helper.js
index 8b40f4fdf..26c8afae9 100644
--- a/lib/less-node/lessc-helper.js
+++ b/lib/less-node/lessc-helper.js
@@ -47,7 +47,8 @@ var lessc_helper = {
console.log(' in generated CSS file.');
console.log(' -rp, --rootpath=URL Sets rootpath for url rewriting in relative imports and urls');
console.log(' Works with or without the relative-urls option.');
- console.log(' -ru, --relative-urls Re-writes relative urls to the base less file.');
+ console.log(' -ru=, --rewrite-urls= Rewrites URLs to make them relative to the base less file.');
+ console.log(' all|local|off \'all\' rewrites all URLs, \'local\' just those starting with a \'.\'');
console.log(' -sm=on|off Turns on or off strict math, where in strict mode, math.');
console.log(' --strict-math=on|off Requires brackets. This option may default to on and then');
console.log(' be removed in the future.');
diff --git a/lib/less-rhino/index.js b/lib/less-rhino/index.js
index 79015eb95..b519a966e 100644
--- a/lib/less-rhino/index.js
+++ b/lib/less-rhino/index.js
@@ -104,16 +104,16 @@ less.Parser.fileLoader = function (file, currentFileInfo, callback, env) {
newFileInfo.entryPath = currentFileInfo.entryPath;
newFileInfo.rootpath = currentFileInfo.rootpath;
newFileInfo.rootFilename = currentFileInfo.rootFilename;
- newFileInfo.relativeUrls = currentFileInfo.relativeUrls;
+ newFileInfo.rewriteUrls = currentFileInfo.rewriteUrls;
} else {
newFileInfo.entryPath = path;
newFileInfo.rootpath = less.rootpath || path;
newFileInfo.rootFilename = href;
- newFileInfo.relativeUrls = env.relativeUrls;
+ newFileInfo.rewriteUrls = env.rewriteUrls;
}
var j = file.lastIndexOf('/');
- if (newFileInfo.relativeUrls && !/^(?:[a-z-]+:|\/)/.test(file) && j != -1) {
+ if (newFileInfo.rewriteUrls && !/^(?:[a-z-]+:|\/)/.test(file) && j != -1) {
var relativeSubDirectory = file.slice(0, j + 1);
newFileInfo.rootpath = newFileInfo.rootpath + relativeSubDirectory; // append (sub|sup) directory path of imported file
}
@@ -307,9 +307,23 @@ function writeFile(filename, content) {
options.rootpath = match[2].replace(/\\/g, '/');
}
break;
- case 'ru':
case 'relative-urls':
- options.relativeUrls = true;
+ print('The relative-urls option has been replaced by the rewrite-urls option and will be removed.');
+ options.rewriteUrls = 'all';
+ break;
+ case 'ru':
+ case 'rewrite-urls':
+ if (match[2] === 'all' || match[2] === 'local') {
+ options.rewriteUrls = match[2];
+ } if (match[2] === 'off') {
+ options.rewriteUrls = false;
+ } else if (!match[2]) {
+ options.rewriteUrls = 'all';
+ } else {
+ print('Unknown rewrite-urls argument ' + match[2]);
+ continueProcessing = false;
+ currentErrorcode = 1;
+ }
break;
case 'sm':
case 'strict-math':
diff --git a/lib/less/contexts.js b/lib/less/contexts.js
index a2f712110..e442dd29d 100644
--- a/lib/less/contexts.js
+++ b/lib/less/contexts.js
@@ -17,7 +17,7 @@ var copyFromOriginal = function copyFromOriginal(original, destination, properti
var parseCopyProperties = [
// options
'paths', // option - unmodified - paths to search for imports on
- 'relativeUrls', // option - whether to adjust URL's to be relative
+ 'rewriteUrls', // option - whether to adjust URL's to be relative
'rootpath', // option - rootpath to append to URL's
'strictImports', // option -
'insecure', // option - whether to allow imports from insecure ssl hosts
@@ -50,7 +50,8 @@ var evalCopyProperties = [
'urlArgs', // whether to add args into url tokens
'javascriptEnabled', // option - whether Inline JavaScript is enabled. if undefined, defaults to false
'pluginManager', // Used as the plugin manager for the session
- 'importantScope' // used to bubble up !important statements
+ 'importantScope', // used to bubble up !important statements
+ 'rewriteUrls' // option - whether to adjust URL's to be relative
];
contexts.Eval = function(options, frames) {
@@ -97,17 +98,36 @@ contexts.Eval.prototype.isMathOn = function () {
return this.strictMath ? (this.parensStack && this.parensStack.length) : true;
};
-contexts.Eval.prototype.isPathRelative = function (path) {
- return !/^(?:[a-z-]+:|\/|#)/i.test(path);
+contexts.Eval.prototype.pathRequiresRewrite = function (path) {
+ var isRelative = this.rewriteUrls === 'local' ? isPathLocalRelative : isPathRelative;
+
+ return isRelative(path);
};
-contexts.Eval.prototype.normalizePath = function( path ) {
+contexts.Eval.prototype.rewritePath = function (path, rootpath) {
+ var newPath;
+
+ rootpath = rootpath || '';
+ newPath = this.normalizePath(rootpath + path);
+
+ // If a path was explicit relative and the rootpath was not an absolute path
+ // we must ensure that the new path is also explicit relative.
+ if (isPathLocalRelative(path) &&
+ isPathRelative(rootpath) &&
+ isPathLocalRelative(newPath) === false) {
+ newPath = './' + newPath;
+ }
+
+ return newPath;
+};
+
+contexts.Eval.prototype.normalizePath = function (path) {
var
segments = path.split('/').reverse(),
segment;
path = [];
- while (segments.length !== 0 ) {
+ while (segments.length !== 0) {
segment = segments.pop();
switch ( segment ) {
case '.':
@@ -120,7 +140,7 @@ contexts.Eval.prototype.normalizePath = function( path ) {
}
break;
default:
- path.push( segment );
+ path.push(segment);
break;
}
}
@@ -128,4 +148,12 @@ contexts.Eval.prototype.normalizePath = function( path ) {
return path.join('/');
};
+function isPathRelative(path) {
+ return !/^(?:[a-z-]+:|\/|#)/i.test(path);
+}
+
+function isPathLocalRelative(path) {
+ return path.charAt(0) === '.';
+}
+
// todo - do the same for the toCSS ?
diff --git a/lib/less/default-options.js b/lib/less/default-options.js
index 09c0b3cfe..9406c63f9 100644
--- a/lib/less/default-options.js
+++ b/lib/less/default-options.js
@@ -39,7 +39,7 @@ module.exports = function() {
* that references an image, exactly the same URL will be output in the css.
* This option allows you to re-write URL's in imported files so that the
* URL is always relative to the base imported file */
- relativeUrls: false,
+ rewriteUrls: false,
/* Compatibility with IE8. Used for limiting data-uri length */
ieCompat: false, // true until 3.0
diff --git a/lib/less/functions/data-uri.js b/lib/less/functions/data-uri.js
index a210589ac..b2452505e 100644
--- a/lib/less/functions/data-uri.js
+++ b/lib/less/functions/data-uri.js
@@ -18,7 +18,7 @@ module.exports = function(environment) {
var mimetype = mimetypeNode && mimetypeNode.value;
var filePath = filePathNode.value;
var currentFileInfo = this.currentFileInfo;
- var currentDirectory = currentFileInfo.relativeUrls ?
+ var currentDirectory = currentFileInfo.rewriteUrls ?
currentFileInfo.currentDirectory : currentFileInfo.entryPath;
var fragmentStart = filePath.indexOf('#');
diff --git a/lib/less/import-manager.js b/lib/less/import-manager.js
index 23b15ba40..2caf117d7 100644
--- a/lib/less/import-manager.js
+++ b/lib/less/import-manager.js
@@ -8,7 +8,7 @@ var contexts = require('./contexts'),
module.exports = function(environment) {
// FileInfo = {
- // 'relativeUrls' - option - whether to adjust URL's to be relative
+ // 'rewriteUrls' - option - whether to adjust URL's to be relative
// 'filename' - full resolved filename of current file
// 'rootpath' - path to append to normal URLs for this node
// 'currentDirectory' - path to the current file, absolute
@@ -65,7 +65,7 @@ module.exports = function(environment) {
};
var newFileInfo = {
- relativeUrls: this.context.relativeUrls,
+ rewriteUrls: this.context.rewriteUrls,
entryPath: currentFileInfo.entryPath,
rootpath: currentFileInfo.rootpath,
rootFilename: currentFileInfo.rootFilename
@@ -92,7 +92,7 @@ module.exports = function(environment) {
// - If path of imported file is '../mixins.less' and rootpath is 'less/',
// then rootpath should become 'less/../'
newFileInfo.currentDirectory = fileManager.getPath(resolvedFilename);
- if (newFileInfo.relativeUrls) {
+ if (newFileInfo.rewriteUrls) {
newFileInfo.rootpath = fileManager.join(
(importManager.context.rootpath || ''),
fileManager.pathDiff(newFileInfo.currentDirectory, newFileInfo.entryPath));
diff --git a/lib/less/parse.js b/lib/less/parse.js
index d1c4fad5d..04b8fdb55 100644
--- a/lib/less/parse.js
+++ b/lib/less/parse.js
@@ -46,7 +46,7 @@ module.exports = function(environment, ParseTree, ImportManager) {
var entryPath = filename.replace(/[^\/\\]*$/, '');
rootFileInfo = {
filename: filename,
- relativeUrls: context.relativeUrls,
+ rewriteUrls: context.rewriteUrls,
rootpath: context.rootpath || '',
currentDirectory: entryPath,
entryPath: entryPath,
diff --git a/lib/less/tree/import.js b/lib/less/tree/import.js
index 53d3f55d0..8d2c0c8b7 100644
--- a/lib/less/tree/import.js
+++ b/lib/less/tree/import.js
@@ -97,17 +97,18 @@ Import.prototype.evalForImport = function (context) {
};
Import.prototype.evalPath = function (context) {
var path = this.path.eval(context);
- var rootpath = this._fileInfo && this._fileInfo.rootpath;
+ var fileInfo = this._fileInfo;
if (!(path instanceof URL)) {
- if (rootpath) {
- var pathValue = path.value;
- // Add the base path if the import is relative
- if (pathValue && context.isPathRelative(pathValue)) {
- path.value = rootpath + pathValue;
- }
+ // Add the rootpath if the URL requires a rewrite
+ var pathValue = path.value;
+ if (fileInfo &&
+ pathValue &&
+ context.pathRequiresRewrite(pathValue)) {
+ path.value = context.rewritePath(pathValue, fileInfo.rootpath);
+ } else {
+ path.value = context.normalizePath(path.value);
}
- path.value = context.normalizePath(path.value);
}
return path;
diff --git a/lib/less/tree/url.js b/lib/less/tree/url.js
index 40d342bf4..234292e2d 100644
--- a/lib/less/tree/url.js
+++ b/lib/less/tree/url.js
@@ -21,20 +21,19 @@ URL.prototype.eval = function (context) {
rootpath;
if (!this.isEvald) {
- // Add the base path if the URL is relative
+ // Add the rootpath if the URL requires a rewrite
rootpath = this.fileInfo() && this.fileInfo().rootpath;
- if (rootpath &&
+ if (typeof rootpath === 'string' &&
typeof val.value === 'string' &&
- context.isPathRelative(val.value)) {
-
+ context.pathRequiresRewrite(val.value)) {
if (!val.quote) {
- rootpath = rootpath.replace(/[\(\)'"\s]/g, function(match) { return '\\' + match; });
+ rootpath = escapePath(rootpath);
}
- val.value = rootpath + val.value;
+ val.value = context.rewritePath(val.value, rootpath);
+ } else {
+ val.value = context.normalizePath(val.value);
}
- val.value = context.normalizePath(val.value);
-
// Add url args if enabled
if (context.urlArgs) {
if (!val.value.match(/^\s*data:/)) {
@@ -51,4 +50,9 @@ URL.prototype.eval = function (context) {
return new URL(val, this.getIndex(), this.fileInfo(), true);
};
+
+function escapePath(path) {
+ return path.replace(/[\(\)'"\s]/g, function(match) { return '\\' + match; });
+}
+
module.exports = URL;
diff --git a/test/browser/css/rewrite-urls/urls.css b/test/browser/css/rewrite-urls/urls.css
new file mode 100644
index 000000000..bf6a90f12
--- /dev/null
+++ b/test/browser/css/rewrite-urls/urls.css
@@ -0,0 +1,36 @@
+@import "http://localhost:8081/test/browser/less/imports/modify-this.css";
+@import "http://localhost:8081/test/browser/less/imports/modify-again.css";
+.modify {
+ my-url: url("http://localhost:8081/test/browser/less/imports/a.png");
+}
+.modify {
+ my-url: url("http://localhost:8081/test/browser/less/imports/b.png");
+}
+@font-face {
+ src: url("/fonts/garamond-pro.ttf");
+ src: local(Futura-Medium), url(http://localhost:8081/test/browser/less/rewrite-urls/fonts.svg#MyGeometricModern) format("svg");
+}
+#shorthands {
+ background: url("http://www.lesscss.org/spec.html") no-repeat 0 4px;
+}
+#misc {
+ background-image: url(http://localhost:8081/test/browser/less/rewrite-urls/images/image.jpg);
+ background: url("#inline-svg");
+}
+#data-uri {
+ background: url(data:image/png;charset=utf-8;base64,
+ kiVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/
+ k//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U
+ kg9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC);
+ background-image: url(data:image/x-png,f9difSSFIIGFIFJD1f982FSDKAA9==);
+ background-image: url(http://fonts.googleapis.com/css?family=\"Rokkitt\":\(400\),700);
+}
+#svg-data-uri {
+ background: transparent url('data:image/svg+xml, ');
+}
+.comma-delimited {
+ background: url(http://localhost:8081/test/browser/less/rewrite-urls/bg.jpg) no-repeat, url(http://localhost:8081/test/browser/less/rewrite-urls/bg.png) repeat-x top left, url(http://localhost:8081/test/browser/less/rewrite-urls/bg);
+}
+.values {
+ url: url('http://localhost:8081/test/browser/less/rewrite-urls/Trebuchet');
+}
diff --git a/test/browser/css/rootpath-rewrite-urls/urls.css b/test/browser/css/rootpath-rewrite-urls/urls.css
new file mode 100644
index 000000000..20b08339d
--- /dev/null
+++ b/test/browser/css/rootpath-rewrite-urls/urls.css
@@ -0,0 +1,35 @@
+@import "https://www.github.com/cloudhead/imports/modify-this.css";
+@import "https://www.github.com/cloudhead/imports/modify-again.css";
+.modify {
+ my-url: url("https://www.github.com/cloudhead/imports/a.png");
+}
+.modify {
+ my-url: url("https://www.github.com/cloudhead/imports/b.png");
+}
+@font-face {
+ src: url("/fonts/garamond-pro.ttf");
+ src: local(Futura-Medium), url(https://www.github.com/cloudhead/less.js/fonts.svg#MyGeometricModern) format("svg");
+}
+#shorthands {
+ background: url("http://www.lesscss.org/spec.html") no-repeat 0 4px;
+}
+#misc {
+ background-image: url(https://www.github.com/cloudhead/less.js/images/image.jpg);
+}
+#data-uri {
+ background: url(data:image/png;charset=utf-8;base64,
+ kiVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/
+ k//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U
+ kg9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC);
+ background-image: url(data:image/x-png,f9difSSFIIGFIFJD1f982FSDKAA9==);
+ background-image: url(http://fonts.googleapis.com/css?family=\"Rokkitt\":\(400\),700);
+}
+#svg-data-uri {
+ background: transparent url('data:image/svg+xml, ');
+}
+.comma-delimited {
+ background: url(https://www.github.com/cloudhead/less.js/bg.jpg) no-repeat, url(https://www.github.com/cloudhead/less.js/bg.png) repeat-x top left, url(https://www.github.com/cloudhead/less.js/bg);
+}
+.values {
+ url: url('https://www.github.com/cloudhead/less.js/Trebuchet');
+}
diff --git a/test/browser/less/rewrite-urls/urls.less b/test/browser/less/rewrite-urls/urls.less
new file mode 100644
index 000000000..0bc8f5ffa
--- /dev/null
+++ b/test/browser/less/rewrite-urls/urls.less
@@ -0,0 +1,34 @@
+@import ".././imports/urls.less";
+@import "http://localhost:8081/test/browser/less/imports/urls2.less";
+@font-face {
+ src: url("/fonts/garamond-pro.ttf");
+ src: local(Futura-Medium),
+ url(fonts.svg#MyGeometricModern) format("svg");
+}
+#shorthands {
+ background: url("http://www.lesscss.org/spec.html") no-repeat 0 4px;
+}
+#misc {
+ background-image: url(images/image.jpg);
+ background: url("#inline-svg");
+}
+#data-uri {
+ background: url(data:image/png;charset=utf-8;base64,
+ kiVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/
+ k//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U
+ kg9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC);
+ background-image: url(data:image/x-png,f9difSSFIIGFIFJD1f982FSDKAA9==);
+ background-image: url(http://fonts.googleapis.com/css?family=\"Rokkitt\":\(400\),700);
+}
+
+#svg-data-uri {
+ background: transparent url('data:image/svg+xml, ');
+}
+
+.comma-delimited {
+ background: url(bg.jpg) no-repeat, url(bg.png) repeat-x top left, url(bg);
+}
+.values {
+ @a: 'Trebuchet';
+ url: url(@a);
+}
diff --git a/test/browser/less/rootpath-rewrite-urls/urls.less b/test/browser/less/rootpath-rewrite-urls/urls.less
new file mode 100644
index 000000000..1843fb224
--- /dev/null
+++ b/test/browser/less/rootpath-rewrite-urls/urls.less
@@ -0,0 +1,33 @@
+@import "../imports/urls.less";
+@import "http://localhost:8081/test/browser/less/imports/urls2.less";
+@font-face {
+ src: url("/fonts/garamond-pro.ttf");
+ src: local(Futura-Medium),
+ url(fonts.svg#MyGeometricModern) format("svg");
+}
+#shorthands {
+ background: url("http://www.lesscss.org/spec.html") no-repeat 0 4px;
+}
+#misc {
+ background-image: url(images/image.jpg);
+}
+#data-uri {
+ background: url(data:image/png;charset=utf-8;base64,
+ kiVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/
+ k//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U
+ kg9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC);
+ background-image: url(data:image/x-png,f9difSSFIIGFIFJD1f982FSDKAA9==);
+ background-image: url(http://fonts.googleapis.com/css?family=\"Rokkitt\":\(400\),700);
+}
+
+#svg-data-uri {
+ background: transparent url('data:image/svg+xml, ');
+}
+
+.comma-delimited {
+ background: url(bg.jpg) no-repeat, url(bg.png) repeat-x top left, url(bg);
+}
+.values {
+ @a: 'Trebuchet';
+ url: url(@a);
+}
diff --git a/test/browser/runner-rewrite-urls-options.js b/test/browser/runner-rewrite-urls-options.js
new file mode 100644
index 000000000..75a0ca628
--- /dev/null
+++ b/test/browser/runner-rewrite-urls-options.js
@@ -0,0 +1,3 @@
+var less = {logLevel: 4,
+ errorReporting: 'console'};
+less.rewriteUrls = 'all';
diff --git a/test/browser/runner-rewrite-urls-spec.js b/test/browser/runner-rewrite-urls-spec.js
new file mode 100644
index 000000000..462f5b80b
--- /dev/null
+++ b/test/browser/runner-rewrite-urls-spec.js
@@ -0,0 +1,3 @@
+describe("less.js browser test - rewrite urls", function() {
+ testLessEqualsInDocument();
+});
diff --git a/test/browser/runner-rootpath-relative-spec.js b/test/browser/runner-rootpath-relative-spec.js
index 69587fb76..9a0d34011 100644
--- a/test/browser/runner-rootpath-relative-spec.js
+++ b/test/browser/runner-rootpath-relative-spec.js
@@ -1,3 +1,3 @@
-describe('less.js browser test - rootpath and relative url\'s', function() {
+describe('less.js browser test - rootpath and relative urls', function() {
testLessEqualsInDocument();
});
diff --git a/test/browser/runner-rootpath-rewrite-urls-options.js b/test/browser/runner-rootpath-rewrite-urls-options.js
new file mode 100644
index 000000000..0372bc61a
--- /dev/null
+++ b/test/browser/runner-rootpath-rewrite-urls-options.js
@@ -0,0 +1,4 @@
+var less = {logLevel: 4,
+ errorReporting: 'console'};
+less.rootpath = 'https://www.github.com/cloudhead/less.js/';
+less.rewriteUrls = 'all';
diff --git a/test/browser/runner-rootpath-rewrite-urls-spec.js b/test/browser/runner-rootpath-rewrite-urls-spec.js
new file mode 100644
index 000000000..c2305831b
--- /dev/null
+++ b/test/browser/runner-rootpath-rewrite-urls-spec.js
@@ -0,0 +1,3 @@
+describe('less.js browser test - rootpath and rewrite urls', function() {
+ testLessEqualsInDocument();
+});
diff --git a/test/css/rewrite-urls-all/rewrite-urls-all.css b/test/css/rewrite-urls-all/rewrite-urls-all.css
new file mode 100644
index 000000000..c3d115dfb
--- /dev/null
+++ b/test/css/rewrite-urls-all/rewrite-urls-all.css
@@ -0,0 +1,17 @@
+#imported-file {
+ background-image: url("./folder/relative/path");
+ background-image: url("./relative/path");
+ background-image: url("../relative/path");
+ background-image: url("folder/module");
+ background-image: url("folder/module/path");
+ background-image: url("folder/module/relative/path");
+}
+#rewrite-urls-all {
+ background-image: url("./relative/path");
+ background-image: url("../relative/path");
+ background-image: url("./path");
+ background-image: url("./");
+ background-image: url("module");
+ background-image: url("module/path");
+ background-image: url("module/relative/path");
+}
diff --git a/test/css/rewrite-urls-local/rewrite-urls-local.css b/test/css/rewrite-urls-local/rewrite-urls-local.css
new file mode 100644
index 000000000..b6ea2801d
--- /dev/null
+++ b/test/css/rewrite-urls-local/rewrite-urls-local.css
@@ -0,0 +1,17 @@
+#imported-file {
+ background-image: url("./folder/relative/path");
+ background-image: url("./relative/path");
+ background-image: url("../relative/path");
+ background-image: url("module");
+ background-image: url("module/path");
+ background-image: url("module/relative/path");
+}
+#rewrite-urls-local {
+ background-image: url("./relative/path");
+ background-image: url("../relative/path");
+ background-image: url("./path");
+ background-image: url("./");
+ background-image: url("module");
+ background-image: url("module/path");
+ background-image: url("module/relative/path");
+}
diff --git a/test/css/rootpath-rewrite-urls-all/rootpath-rewrite-urls-all.css b/test/css/rootpath-rewrite-urls-all/rootpath-rewrite-urls-all.css
new file mode 100644
index 000000000..65421a444
--- /dev/null
+++ b/test/css/rootpath-rewrite-urls-all/rootpath-rewrite-urls-all.css
@@ -0,0 +1,17 @@
+#imported-file {
+ background-image: url("http://example.com/assets/css/folder/relative/path");
+ background-image: url("http://example.com/assets/css/relative/path");
+ background-image: url("http://example.com/assets/relative/path");
+ background-image: url("http://example.com/assets/css/folder/module");
+ background-image: url("http://example.com/assets/css/folder/module/path");
+ background-image: url("http://example.com/assets/css/folder/module/relative/path");
+}
+#rootpath-rewrite-urls-all {
+ background-image: url("http://example.com/assets/css/relative/path");
+ background-image: url("http://example.com/assets/relative/path");
+ background-image: url("http://example.com/assets/css/path");
+ background-image: url("http://example.com/assets/css");
+ background-image: url("http://example.com/assets/css/module");
+ background-image: url("http://example.com/assets/css/module/path");
+ background-image: url("http://example.com/assets/css/module/relative/path");
+}
diff --git a/test/css/rootpath-rewrite-urls-local/rootpath-rewrite-urls-local.css b/test/css/rootpath-rewrite-urls-local/rootpath-rewrite-urls-local.css
new file mode 100644
index 000000000..da99c0f88
--- /dev/null
+++ b/test/css/rootpath-rewrite-urls-local/rootpath-rewrite-urls-local.css
@@ -0,0 +1,17 @@
+#imported-file {
+ background-image: url("http://example.com/assets/css/folder/relative/path");
+ background-image: url("http://example.com/assets/css/relative/path");
+ background-image: url("http://example.com/assets/relative/path");
+ background-image: url("module");
+ background-image: url("module/path");
+ background-image: url("module/relative/path");
+}
+#rootpath-rewrite-urls-local {
+ background-image: url("http://example.com/assets/css/relative/path");
+ background-image: url("http://example.com/assets/relative/path");
+ background-image: url("http://example.com/assets/css/path");
+ background-image: url("http://example.com/assets/css");
+ background-image: url("module");
+ background-image: url("module/path");
+ background-image: url("module/relative/path");
+}
diff --git a/test/css/static-urls/urls.css b/test/css/static-urls/urls.css
index 58678b1a6..e9a417a66 100644
--- a/test/css/static-urls/urls.css
+++ b/test/css/static-urls/urls.css
@@ -30,12 +30,12 @@
#logo {
width: 100px;
height: 100px;
- background: url('assets/logo.png');
+ background: url('./assets/logo.png');
background: url("#inline-svg");
}
@font-face {
font-family: xecret;
- src: url('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 6a9a8db23..5328c0c9c 100644
--- a/test/css/urls.css
+++ b/test/css/urls.css
@@ -38,12 +38,12 @@
#logo {
width: 100px;
height: 100px;
- background: url('import/assets/logo.png');
+ background: url('./import/assets/logo.png');
background: url("#inline-svg");
}
@font-face {
font-family: xecret;
- src: url('import/assets/xecret.ttf');
+ src: url('./import/assets/xecret.ttf');
}
#secret {
font-family: xecret, sans-serif;
diff --git a/test/index.js b/test/index.js
index e28701408..9e5c8f28f 100644
--- a/test/index.js
+++ b/test/index.js
@@ -9,7 +9,8 @@ lessTester.prepBomTest();
var testMap = [
[{
strictMath: false,
- relativeUrls: true,
+ // TODO: Change this to rewriteUrls: 'all' once the relativeUrls option is removed
+ relativeUrls: true,
silent: true,
javascriptEnabled: true,
// Set explicitly for legacy tests for >3.0
@@ -29,6 +30,7 @@ var testMap = [
function(name) { return name + '-mediaquery'; }],
[{strictMath: true, dumpLineNumbers: 'all'}, 'debug/', null,
function(name) { return name + '-all'; }],
+ // TODO: Change this to rewriteUrls: false once the relativeUrls option is removed
[{strictMath: true, relativeUrls: false, rootpath: 'folder (1)/'}, 'static-urls/'],
[{strictMath: true, compress: true}, 'compression/'],
[{strictMath: false, strictUnits: true}, 'strict-units/'],
@@ -48,6 +50,10 @@ var testMap = [
[{modifyVars: true}, 'modifyVars/',
null, null, null, function(name, type, baseFolder) { return path.join(baseFolder, name) + '.json'; }],
[{urlArgs: '424242'}, 'url-args/'],
+ [{rewriteUrls: 'all'}, 'rewrite-urls-all/'],
+ [{rewriteUrls: 'local'}, 'rewrite-urls-local/'],
+ [{rootpath: 'http://example.com/assets/css/', rewriteUrls: 'all'}, 'rootpath-rewrite-urls-all/'],
+ [{rootpath: 'http://example.com/assets/css/', rewriteUrls: 'local'}, 'rootpath-rewrite-urls-local/'],
[{paths: ['test/data/', 'test/less/import/']}, 'include-path/'],
[{paths: 'test/data/'}, 'include-path-string/'],
[{plugin: 'test/plugins/postprocess/'}, 'postProcessorPlugin/'],
diff --git a/test/less/rewrite-urls-all/folder/file.less b/test/less/rewrite-urls-all/folder/file.less
new file mode 100644
index 000000000..7ab3847ed
--- /dev/null
+++ b/test/less/rewrite-urls-all/folder/file.less
@@ -0,0 +1,8 @@
+#imported-file {
+ background-image: url("./relative/path");
+ background-image: url("../relative/path");
+ background-image: url("../../relative/path");
+ background-image: url("module");
+ background-image: url("module/path");
+ background-image: url("module/path/../relative/path");
+}
diff --git a/test/less/rewrite-urls-all/rewrite-urls-all.less b/test/less/rewrite-urls-all/rewrite-urls-all.less
new file mode 100644
index 000000000..aae6d610f
--- /dev/null
+++ b/test/less/rewrite-urls-all/rewrite-urls-all.less
@@ -0,0 +1,11 @@
+@import "./folder/file.less";
+
+#rewrite-urls-all {
+ background-image: url("./relative/path");
+ background-image: url("../relative/path");
+ background-image: url("./relative/../path");
+ background-image: url("./relative/../path/..");
+ background-image: url("module");
+ background-image: url("module/path");
+ background-image: url("module/path/../relative/path");
+}
diff --git a/test/less/rewrite-urls-local/folder/file.less b/test/less/rewrite-urls-local/folder/file.less
new file mode 100644
index 000000000..7ab3847ed
--- /dev/null
+++ b/test/less/rewrite-urls-local/folder/file.less
@@ -0,0 +1,8 @@
+#imported-file {
+ background-image: url("./relative/path");
+ background-image: url("../relative/path");
+ background-image: url("../../relative/path");
+ background-image: url("module");
+ background-image: url("module/path");
+ background-image: url("module/path/../relative/path");
+}
diff --git a/test/less/rewrite-urls-local/rewrite-urls-local.less b/test/less/rewrite-urls-local/rewrite-urls-local.less
new file mode 100644
index 000000000..fb9a40e50
--- /dev/null
+++ b/test/less/rewrite-urls-local/rewrite-urls-local.less
@@ -0,0 +1,11 @@
+@import "./folder/file.less";
+
+#rewrite-urls-local {
+ background-image: url("./relative/path");
+ background-image: url("../relative/path");
+ background-image: url("./relative/../path");
+ background-image: url("./relative/../path/..");
+ background-image: url("module");
+ background-image: url("module/path");
+ background-image: url("module/path/../relative/path");
+}
diff --git a/test/less/rootpath-rewrite-urls-all/folder/file.less b/test/less/rootpath-rewrite-urls-all/folder/file.less
new file mode 100644
index 000000000..7ab3847ed
--- /dev/null
+++ b/test/less/rootpath-rewrite-urls-all/folder/file.less
@@ -0,0 +1,8 @@
+#imported-file {
+ background-image: url("./relative/path");
+ background-image: url("../relative/path");
+ background-image: url("../../relative/path");
+ background-image: url("module");
+ background-image: url("module/path");
+ background-image: url("module/path/../relative/path");
+}
diff --git a/test/less/rootpath-rewrite-urls-all/rootpath-rewrite-urls-all.less b/test/less/rootpath-rewrite-urls-all/rootpath-rewrite-urls-all.less
new file mode 100644
index 000000000..6cf5ff113
--- /dev/null
+++ b/test/less/rootpath-rewrite-urls-all/rootpath-rewrite-urls-all.less
@@ -0,0 +1,11 @@
+@import "./folder/file.less";
+
+#rootpath-rewrite-urls-all {
+ background-image: url("./relative/path");
+ background-image: url("../relative/path");
+ background-image: url("./relative/../path");
+ background-image: url("./relative/../path/..");
+ background-image: url("module");
+ background-image: url("module/path");
+ background-image: url("module/path/../relative/path");
+}
diff --git a/test/less/rootpath-rewrite-urls-local/folder/file.less b/test/less/rootpath-rewrite-urls-local/folder/file.less
new file mode 100644
index 000000000..7ab3847ed
--- /dev/null
+++ b/test/less/rootpath-rewrite-urls-local/folder/file.less
@@ -0,0 +1,8 @@
+#imported-file {
+ background-image: url("./relative/path");
+ background-image: url("../relative/path");
+ background-image: url("../../relative/path");
+ background-image: url("module");
+ background-image: url("module/path");
+ background-image: url("module/path/../relative/path");
+}
diff --git a/test/less/rootpath-rewrite-urls-local/rootpath-rewrite-urls-local.less b/test/less/rootpath-rewrite-urls-local/rootpath-rewrite-urls-local.less
new file mode 100644
index 000000000..d58e40ad1
--- /dev/null
+++ b/test/less/rootpath-rewrite-urls-local/rootpath-rewrite-urls-local.less
@@ -0,0 +1,11 @@
+@import "./folder/file.less";
+
+#rootpath-rewrite-urls-local {
+ background-image: url("./relative/path");
+ background-image: url("../relative/path");
+ background-image: url("./relative/../path");
+ background-image: url("./relative/../path/..");
+ background-image: url("module");
+ background-image: url("module/path");
+ background-image: url("module/path/../relative/path");
+}