From cb4a5779ead291b42e8810deda593e2a9da83cd8 Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Sat, 25 Mar 2017 18:39:37 +0100 Subject: [PATCH 01/10] Rename relativeUrls option to rewriteUrls --- Gruntfile.js | 12 ++++++------ bin/lessc | 8 +++++--- build.gradle | 2 +- lib/less-browser/index.js | 3 ++- lib/less-node/image-size.js | 2 +- lib/less-node/lessc-helper.js | 5 +++-- lib/less-rhino/index.js | 14 ++++++++------ lib/less/contexts.js | 2 +- lib/less/default-options.js | 2 +- lib/less/functions/data-uri.js | 2 +- lib/less/import-manager.js | 6 +++--- lib/less/parse.js | 2 +- .../css/{relative-urls => rewrite-urls}/urls.css | 8 ++++---- .../less/{relative-urls => rewrite-urls}/urls.less | 0 test/browser/runner-relative-urls-spec.js | 3 --- ...s-options.js => runner-rewrite-urls-options.js} | 2 +- test/browser/runner-rewrite-urls-spec.js | 3 +++ test/browser/runner-rootpath-relative-options.js | 2 +- test/browser/runner-rootpath-relative-spec.js | 2 +- test/index.js | 4 ++-- 20 files changed, 45 insertions(+), 39 deletions(-) rename test/browser/css/{relative-urls => rewrite-urls}/urls.css (74%) rename test/browser/less/{relative-urls => rewrite-urls}/urls.less (100%) delete mode 100644 test/browser/runner-relative-urls-spec.js rename test/browser/{runner-relative-urls-options.js => runner-rewrite-urls-options.js} (68%) create mode 100644 test/browser/runner-rewrite-urls-spec.js diff --git a/Gruntfile.js b/Gruntfile.js index 02fe46f9c..560d92bb4 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -74,7 +74,7 @@ module.exports = function (grunt) { "production", "rootpath-relative", "rootpath", - "relative-urls", + "rewrite-urls", "browser", "no-js-errors", "legacy" @@ -325,12 +325,12 @@ module.exports = function (grunt) { outfile: 'tmp/browser/test-runner-browser.html' } }, - relativeUrls: { - src: ['test/browser/less/relative-urls/*.less'], + rewriteUrls: { + src: ['test/browser/less/rewrite-urls/*.less'], options: { - helpers: 'test/browser/runner-relative-urls-options.js', - specs: 'test/browser/runner-relative-urls-spec.js', - outfile: 'tmp/browser/test-runner-relative-urls.html' + 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: { diff --git a/bin/lessc b/bin/lessc index 25cab56c7..132ccb253 100755 --- a/bin/lessc +++ b/bin/lessc @@ -479,9 +479,11 @@ function processPluginQueue() { options.rootpath = match[2].replace(/\\/g, '/'); } break; - case "ru": - case "relative-urls": - options.relativeUrls = true; + case 'relative-urls': + console.warn('The relative-urls option has been replaced by the rewrite-urls option and will be removed'); + case 'ru': + case 'rewrite-urls': + options.rewriteUrls = match[2] || 'all'; 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 5fc2a2b44..d7eb0d5c8 100644 --- a/lib/less-browser/index.js +++ b/lib/less-browser/index.js @@ -99,7 +99,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 01b963902..04368ec8c 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 f283421c7..234f9f3d0 100644 --- a/lib/less-node/lessc-helper.js +++ b/lib/less-node/lessc-helper.js @@ -46,8 +46,9 @@ var lessc_helper = { console.log(" --source-map-url=URL Sets a custom URL to map file, for sourceMappingURL comment"); 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(" Works with or without the rewrite-urls option."); + console.log(" -ru Re-writes urls to make them relative to the base less file."); + console.log(" --rewrite-urls=all|relative 'all' rewrites all URLs, 'relative' 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 b0b745dc1..103083803 100644 --- a/lib/less-rhino/index.js +++ b/lib/less-rhino/index.js @@ -105,16 +105,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 } @@ -308,9 +308,11 @@ function writeFile(filename, content) { options.rootpath = match[2].replace(/\\/g, '/'); } break; - case "ru": - case "relative-urls": - options.relativeUrls = true; + case 'relative-urls': + console.warn('The relative-urls option has been replaced by the rewrite-urls option and will be removed'); + case 'ru': + case 'rewrite-urls': + options.rewriteUrls = match[2] || 'all'; break; case "sm": case "strict-math": diff --git a/lib/less/contexts.js b/lib/less/contexts.js index 06190edff..4ae1ba957 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 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 2bd373828..e6bedf0f3 100644 --- a/lib/less/functions/data-uri.js +++ b/lib/less/functions/data-uri.js @@ -17,7 +17,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 4d298b96a..bce2e8b17 100644 --- a/lib/less/import-manager.js +++ b/lib/less/import-manager.js @@ -5,7 +5,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 @@ -55,7 +55,7 @@ module.exports = function(environment) { }; var newFileInfo = { - relativeUrls: this.context.relativeUrls, + rewriteUrls: this.context.rewriteUrls, entryPath: currentFileInfo.entryPath, rootpath: currentFileInfo.rootpath, rootFilename: currentFileInfo.rootFilename @@ -86,7 +86,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 125bdff4f..184d9aa1f 100644 --- a/lib/less/parse.js +++ b/lib/less/parse.js @@ -43,7 +43,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/test/browser/css/relative-urls/urls.css b/test/browser/css/rewrite-urls/urls.css similarity index 74% rename from test/browser/css/relative-urls/urls.css rename to test/browser/css/rewrite-urls/urls.css index 8a62a8955..bf6a90f12 100644 --- a/test/browser/css/relative-urls/urls.css +++ b/test/browser/css/rewrite-urls/urls.css @@ -8,13 +8,13 @@ } @font-face { src: url("/fonts/garamond-pro.ttf"); - src: local(Futura-Medium), url(http://localhost:8081/test/browser/less/relative-urls/fonts.svg#MyGeometricModern) format("svg"); + 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/relative-urls/images/image.jpg); + background-image: url(http://localhost:8081/test/browser/less/rewrite-urls/images/image.jpg); background: url("#inline-svg"); } #data-uri { @@ -29,8 +29,8 @@ background: transparent url('data:image/svg+xml, '); } .comma-delimited { - background: url(http://localhost:8081/test/browser/less/relative-urls/bg.jpg) no-repeat, url(http://localhost:8081/test/browser/less/relative-urls/bg.png) repeat-x top left, url(http://localhost:8081/test/browser/less/relative-urls/bg); + 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/relative-urls/Trebuchet'); + url: url('http://localhost:8081/test/browser/less/rewrite-urls/Trebuchet'); } diff --git a/test/browser/less/relative-urls/urls.less b/test/browser/less/rewrite-urls/urls.less similarity index 100% rename from test/browser/less/relative-urls/urls.less rename to test/browser/less/rewrite-urls/urls.less diff --git a/test/browser/runner-relative-urls-spec.js b/test/browser/runner-relative-urls-spec.js deleted file mode 100644 index b13911ee8..000000000 --- a/test/browser/runner-relative-urls-spec.js +++ /dev/null @@ -1,3 +0,0 @@ -describe("less.js browser test - relative url's", function() { - testLessEqualsInDocument(); -}); diff --git a/test/browser/runner-relative-urls-options.js b/test/browser/runner-rewrite-urls-options.js similarity index 68% rename from test/browser/runner-relative-urls-options.js rename to test/browser/runner-rewrite-urls-options.js index e5ebfd2bf..8cde7ba00 100644 --- a/test/browser/runner-relative-urls-options.js +++ b/test/browser/runner-rewrite-urls-options.js @@ -1,3 +1,3 @@ var less = {logLevel: 4, errorReporting: "console"}; -less.relativeUrls = true; +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-options.js b/test/browser/runner-rootpath-relative-options.js index 641bab8fc..678befea1 100644 --- a/test/browser/runner-rootpath-relative-options.js +++ b/test/browser/runner-rootpath-relative-options.js @@ -1,4 +1,4 @@ var less = {logLevel: 4, errorReporting: "console"}; less.rootpath = "https://www.github.com/cloudhead/less.js/"; -less.relativeUrls = true; +less.rewriteUrls = "all"; diff --git a/test/browser/runner-rootpath-relative-spec.js b/test/browser/runner-rootpath-relative-spec.js index cd905739a..991b5f7bd 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 rewrite urls", function() { testLessEqualsInDocument(); }); diff --git a/test/index.js b/test/index.js index 09f24a146..43e3b290d 100644 --- a/test/index.js +++ b/test/index.js @@ -7,7 +7,7 @@ console.log("\n" + stylize("Less", 'underline') + "\n"); lessTester.prepBomTest(); var testMap = [ - [{strictMath: true, relativeUrls: true, silent: true, javascriptEnabled: true}], + [{strictMath: true, rewriteUrls: 'all', silent: true, javascriptEnabled: true}], [{strictMath: true, strictUnits: true, javascriptEnabled: true}, "errors/", lessTester.testErrors, null], [{strictMath: true, strictUnits: true, javascriptEnabled: false}, "no-js-errors/", @@ -18,7 +18,7 @@ var testMap = [ function(name) { return name + '-mediaquery'; }], [{strictMath: true, dumpLineNumbers: 'all'}, "debug/", null, function(name) { return name + '-all'; }], - [{strictMath: true, relativeUrls: false, rootpath: "folder (1)/"}, "static-urls/"], + [{strictMath: true, rewriteUrls: false, rootpath: "folder (1)/"}, "static-urls/"], [{strictMath: true, compress: true}, "compression/"], [{strictMath: false, strictUnits: true}, "strict-units/"], [{}, "legacy/"], From b95c294157060cb24109a1a4fd1cd59c6b85cae5 Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Mon, 27 Mar 2017 20:59:01 +0200 Subject: [PATCH 02/10] Refactor contexts.js - Rename isPathRelative to pathRequiresRewrite - Add special handling for rewriteUrls=relative - Add rewritePath for path rewriting - Ensure that explicit relative paths stay explicit relative - Remove code style inconsistencies --- lib/less/contexts.js | 56 ++++++++++++++++++++++++++--------- lib/less/tree/import.js | 17 ++++++----- lib/less/tree/url.js | 26 +++++++++------- test/css/static-urls/urls.css | 4 +-- test/css/urls.css | 4 +-- 5 files changed, 71 insertions(+), 36 deletions(-) diff --git a/lib/less/contexts.js b/lib/less/contexts.js index 4ae1ba957..a2f837927 100644 --- a/lib/less/contexts.js +++ b/lib/less/contexts.js @@ -36,11 +36,12 @@ var parseCopyProperties = [ contexts.Parse = function(options) { copyFromOriginal(options, this, parseCopyProperties); - if (typeof this.paths === "string") { this.paths = [this.paths]; } + if (typeof this.paths === 'string') { this.paths = [this.paths]; } }; var evalCopyProperties = [ 'paths', // additional include paths + 'rewriteUrls', // option - whether to adjust URL's to be relative 'compress', // whether to compress 'ieCompat', // whether to enforce IE compatibility (IE8 data-uri) 'strictMath', // whether math has to be within parenthesis @@ -56,7 +57,7 @@ var evalCopyProperties = [ contexts.Eval = function(options, frames) { copyFromOriginal(options, this, evalCopyProperties); - if (typeof this.paths === "string") { this.paths = [this.paths]; } + if (typeof this.paths === 'string') { this.paths = [this.paths]; } this.frames = frames || []; this.importantScope = this.importantScope || []; @@ -77,35 +78,62 @@ 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 === 'relative' ? isPathExplicitRelative : 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 (isPathExplicitRelative(path) && + isPathRelative(rootpath) && + isPathExplicitRelative(newPath) === false) { + newPath = './' + newPath; + } + + return newPath; +}; + +contexts.Eval.prototype.normalizePath = function (path) { var - segments = path.split("/").reverse(), + segments = path.split('/').reverse(), segment; path = []; - while (segments.length !== 0 ) { + while (segments.length !== 0) { segment = segments.pop(); - switch ( segment ) { - case ".": + switch (segment) { + case '.': break; - case "..": - if ((path.length === 0) || (path[path.length - 1] === "..")) { - path.push( segment ); + case '..': + if ((path.length === 0) || (path[path.length - 1] === '..')) { + path.push(segment); } else { path.pop(); } break; default: - path.push( segment ); + path.push(segment); break; } } - return path.join("/"); + return path.join('/'); }; +function isPathRelative(path) { + return !/^(?:[a-z-]+:|\/|#)/i.test(path); +} + +function isPathExplicitRelative(path) { + return path.charAt(0) === '.'; +} + //todo - do the same for the toCSS ? diff --git a/lib/less/tree/import.js b/lib/less/tree/import.js index b459bb392..adc04a518 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 fa0d4c871..d94f20338 100644 --- a/lib/less/tree/url.js +++ b/lib/less/tree/url.js @@ -18,23 +18,24 @@ URL.prototype.genCSS = function (context, output) { }; URL.prototype.eval = function (context) { var val = this.value.eval(context), + fileInfo, rootpath; if (!this.isEvald) { - // Add the base path if the URL is relative - rootpath = this.fileInfo() && this.fileInfo().rootpath; - if (rootpath && - typeof val.value === "string" && - context.isPathRelative(val.value)) { - + // Add the rootpath if the URL requires a rewrite + fileInfo = this.fileInfo(); + rootpath = fileInfo && fileInfo.rootpath; + if (typeof rootpath === 'string' && + typeof val.value === 'string' && + 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 +52,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/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; From 99df16a9c612674a1ec3dccd123ab422cd5920f3 Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Tue, 28 Mar 2017 03:10:51 +0200 Subject: [PATCH 03/10] Add missing tests for url rewriting --- .../css/rewrite-urls-all/rewrite-urls-all.css | 23 +++++++++++++++++++ .../rewrite-urls-relative.css | 23 +++++++++++++++++++ test/index.js | 2 ++ test/less/rewrite-urls-all/folder/file.less | 8 +++++++ .../rewrite-urls-all/rewrite-urls-all.less | 17 ++++++++++++++ .../rewrite-urls-relative/folder/file.less | 8 +++++++ .../rewrite-urls-relative.less | 17 ++++++++++++++ 7 files changed, 98 insertions(+) create mode 100644 test/css/rewrite-urls-all/rewrite-urls-all.css create mode 100644 test/css/rewrite-urls-relative/rewrite-urls-relative.css create mode 100644 test/less/rewrite-urls-all/folder/file.less create mode 100644 test/less/rewrite-urls-all/rewrite-urls-all.less create mode 100644 test/less/rewrite-urls-relative/folder/file.less create mode 100644 test/less/rewrite-urls-relative/rewrite-urls-relative.less 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..95de28c4a --- /dev/null +++ b/test/css/rewrite-urls-all/rewrite-urls-all.css @@ -0,0 +1,23 @@ +#imported-file { + background-url: url(./folder/relative/path); + background-url: url(./relative/path); + background-url: url(../relative/path); + background-url: url(folder/module); + background-url: url(folder/module/path); + background-url: url(folder/module/relative/path); +} +#correct-normalize { + background-url: url(./relative/path); + background-url: url("./relative/path"); + background-url: url('./relative/path'); + background-url: url(../relative/path); + background-url: url("../relative/path"); + background-url: url('../relative/path'); + background-url: url(./path); + background-url: url(./); + background-url: url(module); + background-url: url(module/path); + background-url: url("module"); + background-url: url("module/path"); + background-url: url(module/relative/path); +} diff --git a/test/css/rewrite-urls-relative/rewrite-urls-relative.css b/test/css/rewrite-urls-relative/rewrite-urls-relative.css new file mode 100644 index 000000000..e248ca46b --- /dev/null +++ b/test/css/rewrite-urls-relative/rewrite-urls-relative.css @@ -0,0 +1,23 @@ +#imported-file { + background-url: url(./folder/relative/path); + background-url: url(./relative/path); + background-url: url(../relative/path); + background-url: url(module); + background-url: url(module/path); + background-url: url(module/relative/path); +} +#correct-normalize { + background-url: url(./relative/path); + background-url: url("./relative/path"); + background-url: url('./relative/path'); + background-url: url(../relative/path); + background-url: url("../relative/path"); + background-url: url('../relative/path'); + background-url: url(./path); + background-url: url(./); + background-url: url(module); + background-url: url(module/path); + background-url: url("module"); + background-url: url("module/path"); + background-url: url(module/relative/path); +} diff --git a/test/index.js b/test/index.js index 43e3b290d..1fc4ef0e7 100644 --- a/test/index.js +++ b/test/index.js @@ -37,6 +37,8 @@ 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: 'relative'}, 'rewrite-urls-relative/'], [{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..a73c8287d --- /dev/null +++ b/test/less/rewrite-urls-all/folder/file.less @@ -0,0 +1,8 @@ +#imported-file { + background-url: url(./relative/path); + background-url: url(../relative/path); + background-url: url(../../relative/path); + background-url: url(module); + background-url: url(module/path); + background-url: 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..6640f1455 --- /dev/null +++ b/test/less/rewrite-urls-all/rewrite-urls-all.less @@ -0,0 +1,17 @@ +@import "./folder/file.less"; + +#correct-normalize { + background-url: url(./relative/path); + background-url: url("./relative/path"); + background-url: url('./relative/path'); + background-url: url(../relative/path); + background-url: url("../relative/path"); + background-url: url('../relative/path'); + background-url: url(./relative/../path); + background-url: url(./relative/../path/..); + background-url: url(module); + background-url: url(module/path); + background-url: url("module"); + background-url: url("module/path"); + background-url: url(module/path/../relative/path); +} diff --git a/test/less/rewrite-urls-relative/folder/file.less b/test/less/rewrite-urls-relative/folder/file.less new file mode 100644 index 000000000..a73c8287d --- /dev/null +++ b/test/less/rewrite-urls-relative/folder/file.less @@ -0,0 +1,8 @@ +#imported-file { + background-url: url(./relative/path); + background-url: url(../relative/path); + background-url: url(../../relative/path); + background-url: url(module); + background-url: url(module/path); + background-url: url(module/path/../relative/path); +} diff --git a/test/less/rewrite-urls-relative/rewrite-urls-relative.less b/test/less/rewrite-urls-relative/rewrite-urls-relative.less new file mode 100644 index 000000000..6640f1455 --- /dev/null +++ b/test/less/rewrite-urls-relative/rewrite-urls-relative.less @@ -0,0 +1,17 @@ +@import "./folder/file.less"; + +#correct-normalize { + background-url: url(./relative/path); + background-url: url("./relative/path"); + background-url: url('./relative/path'); + background-url: url(../relative/path); + background-url: url("../relative/path"); + background-url: url('../relative/path'); + background-url: url(./relative/../path); + background-url: url(./relative/../path/..); + background-url: url(module); + background-url: url(module/path); + background-url: url("module"); + background-url: url("module/path"); + background-url: url(module/path/../relative/path); +} From e80a91dd269f3672248c3943fd7111f61abf780c Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Tue, 28 Mar 2017 03:26:12 +0200 Subject: [PATCH 04/10] Rename rewrite-urls option value to explicit-relative --- lib/less-node/lessc-helper.js | 6 +++--- lib/less/contexts.js | 2 +- test/index.js | 2 +- .../folder/file.less | 0 .../rewrite-urls-explicit-relative} | 0 5 files changed, 5 insertions(+), 5 deletions(-) rename test/less/{rewrite-urls-relative => rewrite-urls-explicit-relative}/folder/file.less (100%) rename test/less/{rewrite-urls-relative/rewrite-urls-relative.less => rewrite-urls-explicit-relative/rewrite-urls-explicit-relative} (100%) diff --git a/lib/less-node/lessc-helper.js b/lib/less-node/lessc-helper.js index 234f9f3d0..80fe7fcb3 100644 --- a/lib/less-node/lessc-helper.js +++ b/lib/less-node/lessc-helper.js @@ -45,10 +45,10 @@ var lessc_helper = { console.log(" --source-map-inline Puts the map (and any less files) as a base64 data uri into the output css file."); console.log(" --source-map-url=URL Sets a custom URL to map file, for sourceMappingURL comment"); console.log(" in generated CSS file."); - console.log(" -rp, --rootpath=URL Sets rootpath for url rewriting in relative imports and urls"); + console.log(" -rp=, --rootpath=URL Sets rootpath for url rewriting in relative imports and urls"); console.log(" Works with or without the rewrite-urls option."); - console.log(" -ru Re-writes urls to make them relative to the base less file."); - console.log(" --rewrite-urls=all|relative 'all' rewrites all URLs, 'relative' just those starting with a '.'") + console.log(" -ru=, --rewrite-urls= Rewrites URLs to make them relative to the base less file."); + console.log(" all|explicit-relative 'all' rewrites all URLs, 'explicit-relative' 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/contexts.js b/lib/less/contexts.js index a2f837927..b56683793 100644 --- a/lib/less/contexts.js +++ b/lib/less/contexts.js @@ -79,7 +79,7 @@ contexts.Eval.prototype.isMathOn = function () { }; contexts.Eval.prototype.pathRequiresRewrite = function (path) { - var isRelative = this.rewriteUrls === 'relative' ? isPathExplicitRelative : isPathRelative; + var isRelative = this.rewriteUrls === 'explicit-relative' ? isPathExplicitRelative : isPathRelative; return isRelative(path); }; diff --git a/test/index.js b/test/index.js index 1fc4ef0e7..697769386 100644 --- a/test/index.js +++ b/test/index.js @@ -38,7 +38,7 @@ var testMap = [ null, null, null, function(name, type, baseFolder) { return path.join(baseFolder, name) + '.json'; }], [{urlArgs: '424242'}, "url-args/"], [{rewriteUrls: 'all'}, 'rewrite-urls-all/'], - [{rewriteUrls: 'relative'}, 'rewrite-urls-relative/'], + [{rewriteUrls: 'explicit-relative'}, 'rewrite-urls-explicit-relative/'], [{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-relative/folder/file.less b/test/less/rewrite-urls-explicit-relative/folder/file.less similarity index 100% rename from test/less/rewrite-urls-relative/folder/file.less rename to test/less/rewrite-urls-explicit-relative/folder/file.less diff --git a/test/less/rewrite-urls-relative/rewrite-urls-relative.less b/test/less/rewrite-urls-explicit-relative/rewrite-urls-explicit-relative similarity index 100% rename from test/less/rewrite-urls-relative/rewrite-urls-relative.less rename to test/less/rewrite-urls-explicit-relative/rewrite-urls-explicit-relative From bfc78129ca0163ee75489a291c743c8c37692d94 Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Tue, 28 Mar 2017 03:50:16 +0200 Subject: [PATCH 05/10] Add missing tests for url rewriting --- .../rewrite-urls-explicit-relative.css} | 0 ...urls-explicit-relative => rewrite-urls-explicit-relative.less} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename test/css/{rewrite-urls-relative/rewrite-urls-relative.css => rewrite-urls-explicit-relative/rewrite-urls-explicit-relative.css} (100%) rename test/less/rewrite-urls-explicit-relative/{rewrite-urls-explicit-relative => rewrite-urls-explicit-relative.less} (100%) diff --git a/test/css/rewrite-urls-relative/rewrite-urls-relative.css b/test/css/rewrite-urls-explicit-relative/rewrite-urls-explicit-relative.css similarity index 100% rename from test/css/rewrite-urls-relative/rewrite-urls-relative.css rename to test/css/rewrite-urls-explicit-relative/rewrite-urls-explicit-relative.css diff --git a/test/less/rewrite-urls-explicit-relative/rewrite-urls-explicit-relative b/test/less/rewrite-urls-explicit-relative/rewrite-urls-explicit-relative.less similarity index 100% rename from test/less/rewrite-urls-explicit-relative/rewrite-urls-explicit-relative rename to test/less/rewrite-urls-explicit-relative/rewrite-urls-explicit-relative.less From c2eea6ba62259145e94589d9cd9e8c0e7e19c106 Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Tue, 26 Jun 2018 13:51:41 +0200 Subject: [PATCH 06/10] Refactor rewrite urls options - Rename explicit-relative to local - Add rewrite-urls argument validation - Replace unknown CSS property background-url with background-image Based on discussion https://github.com/less/less.js/pull/3041 --- bin/lessc | 14 ++++++- lib/less-node/lessc-helper.js | 2 +- lib/less-rhino/index.js | 16 +++++++- lib/less/contexts.js | 8 ++-- test/browser/runner-rewrite-urls-options.js | 1 - .../css/rewrite-urls-all/rewrite-urls-all.css | 40 +++++++++---------- .../rewrite-urls-explicit-relative.css | 23 ----------- .../rewrite-urls-local/rewrite-urls-local.css | 23 +++++++++++ test/index.js | 2 +- test/less/rewrite-urls-all/folder/file.less | 12 +++--- .../rewrite-urls-all/rewrite-urls-all.less | 28 ++++++------- .../folder/file.less | 8 ---- .../rewrite-urls-explicit-relative.less | 17 -------- test/less/rewrite-urls-local/folder/file.less | 8 ++++ .../rewrite-urls-local.less | 17 ++++++++ 15 files changed, 121 insertions(+), 98 deletions(-) delete mode 100644 test/css/rewrite-urls-explicit-relative/rewrite-urls-explicit-relative.css create mode 100644 test/css/rewrite-urls-local/rewrite-urls-local.css delete mode 100644 test/less/rewrite-urls-explicit-relative/folder/file.less delete mode 100644 test/less/rewrite-urls-explicit-relative/rewrite-urls-explicit-relative.less create mode 100644 test/less/rewrite-urls-local/folder/file.less create mode 100644 test/less/rewrite-urls-local/rewrite-urls-local.less diff --git a/bin/lessc b/bin/lessc index 5d7ea4305..380aa1e90 100755 --- a/bin/lessc +++ b/bin/lessc @@ -477,9 +477,21 @@ function processPluginQueue() { break; case 'relative-urls': 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': - options.rewriteUrls = match[2] || 'all'; + 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 { + console.error('Unkown rewrite-urls argument ' + match[2]); + continueProcessing = false; + process.exitCode = 1; + } break; case 'sm': case 'strict-math': diff --git a/lib/less-node/lessc-helper.js b/lib/less-node/lessc-helper.js index 8784bdc5e..26c8afae9 100644 --- a/lib/less-node/lessc-helper.js +++ b/lib/less-node/lessc-helper.js @@ -48,7 +48,7 @@ var lessc_helper = { 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=, --rewrite-urls= Rewrites URLs to make them relative to the base less file.'); - console.log(' all|explicit-relative \'all\' rewrites all URLs, \'explicit-relative\' just those starting with a \'.\''); + 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 b0685a7c2..65ae6cab1 100644 --- a/lib/less-rhino/index.js +++ b/lib/less-rhino/index.js @@ -308,10 +308,22 @@ function writeFile(filename, content) { } break; case 'relative-urls': - console.warn('The relative-urls option has been replaced by the rewrite-urls option and will be removed'); + 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': - options.rewriteUrls = match[2] || 'all'; + 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('Unkown 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 b6d0299ac..e442dd29d 100644 --- a/lib/less/contexts.js +++ b/lib/less/contexts.js @@ -99,7 +99,7 @@ contexts.Eval.prototype.isMathOn = function () { }; contexts.Eval.prototype.pathRequiresRewrite = function (path) { - var isRelative = this.rewriteUrls === 'explicit-relative' ? isPathExplicitRelative : isPathRelative; + var isRelative = this.rewriteUrls === 'local' ? isPathLocalRelative : isPathRelative; return isRelative(path); }; @@ -112,9 +112,9 @@ contexts.Eval.prototype.rewritePath = function (path, rootpath) { // 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 (isPathExplicitRelative(path) && + if (isPathLocalRelative(path) && isPathRelative(rootpath) && - isPathExplicitRelative(newPath) === false) { + isPathLocalRelative(newPath) === false) { newPath = './' + newPath; } @@ -152,7 +152,7 @@ function isPathRelative(path) { return !/^(?:[a-z-]+:|\/|#)/i.test(path); } -function isPathExplicitRelative(path) { +function isPathLocalRelative(path) { return path.charAt(0) === '.'; } diff --git a/test/browser/runner-rewrite-urls-options.js b/test/browser/runner-rewrite-urls-options.js index bf7fff5da..75a0ca628 100644 --- a/test/browser/runner-rewrite-urls-options.js +++ b/test/browser/runner-rewrite-urls-options.js @@ -1,4 +1,3 @@ var less = {logLevel: 4, - errorReporting: 'console'}; less.rewriteUrls = 'all'; diff --git a/test/css/rewrite-urls-all/rewrite-urls-all.css b/test/css/rewrite-urls-all/rewrite-urls-all.css index 95de28c4a..2082bdcd3 100644 --- a/test/css/rewrite-urls-all/rewrite-urls-all.css +++ b/test/css/rewrite-urls-all/rewrite-urls-all.css @@ -1,23 +1,23 @@ #imported-file { - background-url: url(./folder/relative/path); - background-url: url(./relative/path); - background-url: url(../relative/path); - background-url: url(folder/module); - background-url: url(folder/module/path); - background-url: url(folder/module/relative/path); + 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); } -#correct-normalize { - background-url: url(./relative/path); - background-url: url("./relative/path"); - background-url: url('./relative/path'); - background-url: url(../relative/path); - background-url: url("../relative/path"); - background-url: url('../relative/path'); - background-url: url(./path); - background-url: url(./); - background-url: url(module); - background-url: url(module/path); - background-url: url("module"); - background-url: url("module/path"); - background-url: url(module/relative/path); +#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("../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"); + background-image: url("module/path"); + background-image: url(module/relative/path); } diff --git a/test/css/rewrite-urls-explicit-relative/rewrite-urls-explicit-relative.css b/test/css/rewrite-urls-explicit-relative/rewrite-urls-explicit-relative.css deleted file mode 100644 index e248ca46b..000000000 --- a/test/css/rewrite-urls-explicit-relative/rewrite-urls-explicit-relative.css +++ /dev/null @@ -1,23 +0,0 @@ -#imported-file { - background-url: url(./folder/relative/path); - background-url: url(./relative/path); - background-url: url(../relative/path); - background-url: url(module); - background-url: url(module/path); - background-url: url(module/relative/path); -} -#correct-normalize { - background-url: url(./relative/path); - background-url: url("./relative/path"); - background-url: url('./relative/path'); - background-url: url(../relative/path); - background-url: url("../relative/path"); - background-url: url('../relative/path'); - background-url: url(./path); - background-url: url(./); - background-url: url(module); - background-url: url(module/path); - background-url: url("module"); - background-url: url("module/path"); - background-url: 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..99c287d40 --- /dev/null +++ b/test/css/rewrite-urls-local/rewrite-urls-local.css @@ -0,0 +1,23 @@ +#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('./relative/path'); + background-image: url(../relative/path); + 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"); + background-image: url("module/path"); + background-image: url(module/relative/path); +} diff --git a/test/index.js b/test/index.js index b092297f7..06c4e26f1 100644 --- a/test/index.js +++ b/test/index.js @@ -49,7 +49,7 @@ var testMap = [ null, null, null, function(name, type, baseFolder) { return path.join(baseFolder, name) + '.json'; }], [{urlArgs: '424242'}, 'url-args/'], [{rewriteUrls: 'all'}, 'rewrite-urls-all/'], - [{rewriteUrls: 'explicit-relative'}, 'rewrite-urls-explicit-relative/'], + [{rewriteUrls: 'local'}, '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 index a73c8287d..77495908e 100644 --- a/test/less/rewrite-urls-all/folder/file.less +++ b/test/less/rewrite-urls-all/folder/file.less @@ -1,8 +1,8 @@ #imported-file { - background-url: url(./relative/path); - background-url: url(../relative/path); - background-url: url(../../relative/path); - background-url: url(module); - background-url: url(module/path); - background-url: url(module/path/../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-all/rewrite-urls-all.less b/test/less/rewrite-urls-all/rewrite-urls-all.less index 6640f1455..0959612ba 100644 --- a/test/less/rewrite-urls-all/rewrite-urls-all.less +++ b/test/less/rewrite-urls-all/rewrite-urls-all.less @@ -1,17 +1,17 @@ @import "./folder/file.less"; -#correct-normalize { - background-url: url(./relative/path); - background-url: url("./relative/path"); - background-url: url('./relative/path'); - background-url: url(../relative/path); - background-url: url("../relative/path"); - background-url: url('../relative/path'); - background-url: url(./relative/../path); - background-url: url(./relative/../path/..); - background-url: url(module); - background-url: url(module/path); - background-url: url("module"); - background-url: url("module/path"); - background-url: url(module/path/../relative/path); +#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("../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"); + background-image: url("module/path"); + background-image: url(module/path/../relative/path); } diff --git a/test/less/rewrite-urls-explicit-relative/folder/file.less b/test/less/rewrite-urls-explicit-relative/folder/file.less deleted file mode 100644 index a73c8287d..000000000 --- a/test/less/rewrite-urls-explicit-relative/folder/file.less +++ /dev/null @@ -1,8 +0,0 @@ -#imported-file { - background-url: url(./relative/path); - background-url: url(../relative/path); - background-url: url(../../relative/path); - background-url: url(module); - background-url: url(module/path); - background-url: url(module/path/../relative/path); -} diff --git a/test/less/rewrite-urls-explicit-relative/rewrite-urls-explicit-relative.less b/test/less/rewrite-urls-explicit-relative/rewrite-urls-explicit-relative.less deleted file mode 100644 index 6640f1455..000000000 --- a/test/less/rewrite-urls-explicit-relative/rewrite-urls-explicit-relative.less +++ /dev/null @@ -1,17 +0,0 @@ -@import "./folder/file.less"; - -#correct-normalize { - background-url: url(./relative/path); - background-url: url("./relative/path"); - background-url: url('./relative/path'); - background-url: url(../relative/path); - background-url: url("../relative/path"); - background-url: url('../relative/path'); - background-url: url(./relative/../path); - background-url: url(./relative/../path/..); - background-url: url(module); - background-url: url(module/path); - background-url: url("module"); - background-url: url("module/path"); - background-url: 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..77495908e --- /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..8ea28d3ae --- /dev/null +++ b/test/less/rewrite-urls-local/rewrite-urls-local.less @@ -0,0 +1,17 @@ +@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("../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"); + background-image: url("module/path"); + background-image: url(module/path/../relative/path); +} From 78b5254b9950be3bfc8f5ff0901349587be2a07c Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Tue, 26 Jun 2018 13:52:07 +0200 Subject: [PATCH 07/10] Re-add tests for deprecated relative-urls option --- Gruntfile.js | 21 ++++++++++- lib/less-browser/index.js | 4 +++ test/browser/css/relative-urls/urls.css | 36 +++++++++++++++++++ .../css/rootpath-rewrite-urls/urls.css | 35 ++++++++++++++++++ test/browser/less/relative-urls/urls.less | 34 ++++++++++++++++++ .../less/rootpath-rewrite-urls/urls.less | 33 +++++++++++++++++ test/browser/runner-relative-urls-options.js | 3 ++ test/browser/runner-relative-urls-spec.js | 3 ++ .../runner-rootpath-relative-options.js | 2 +- test/browser/runner-rootpath-relative-spec.js | 2 +- .../runner-rootpath-rewrite-urls-options.js | 4 +++ .../runner-rootpath-rewrite-urls-spec.js | 3 ++ 12 files changed, 177 insertions(+), 3 deletions(-) create mode 100644 test/browser/css/relative-urls/urls.css create mode 100644 test/browser/css/rootpath-rewrite-urls/urls.css create mode 100644 test/browser/less/relative-urls/urls.less create mode 100644 test/browser/less/rootpath-rewrite-urls/urls.less create mode 100644 test/browser/runner-relative-urls-options.js create mode 100644 test/browser/runner-relative-urls-spec.js create mode 100644 test/browser/runner-rootpath-rewrite-urls-options.js create mode 100644 test/browser/runner-rootpath-rewrite-urls-spec.js diff --git a/Gruntfile.js b/Gruntfile.js index 4bcc600c6..c90ab2b48 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -71,13 +71,16 @@ 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', @@ -351,6 +354,14 @@ module.exports = function (grunt) { outfile: 'tmp/browser/test-runner-browser.html' } }, + relativeUrls: { + src: ['test/browser/less/relative-urls/*.less'], + options: { + helpers: 'test/browser/runner-relative-urls-options.js', + specs: 'test/browser/runner-relative-urls-spec.js', + outfile: 'tmp/browser/test-runner-relative-urls.html' + } + }, rewriteUrls: { src: ['test/browser/less/rewrite-urls/*.less'], options: { @@ -375,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/lib/less-browser/index.js b/lib/less-browser/index.js index 9af05b2bf..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$/; diff --git a/test/browser/css/relative-urls/urls.css b/test/browser/css/relative-urls/urls.css new file mode 100644 index 000000000..8a62a8955 --- /dev/null +++ b/test/browser/css/relative-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/relative-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/relative-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/relative-urls/bg.jpg) no-repeat, url(http://localhost:8081/test/browser/less/relative-urls/bg.png) repeat-x top left, url(http://localhost:8081/test/browser/less/relative-urls/bg); +} +.values { + url: url('http://localhost:8081/test/browser/less/relative-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/relative-urls/urls.less b/test/browser/less/relative-urls/urls.less new file mode 100644 index 000000000..0bc8f5ffa --- /dev/null +++ b/test/browser/less/relative-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-relative-urls-options.js b/test/browser/runner-relative-urls-options.js new file mode 100644 index 000000000..43f670e4e --- /dev/null +++ b/test/browser/runner-relative-urls-options.js @@ -0,0 +1,3 @@ +var less = {logLevel: 4, + errorReporting: 'console'}; +less.relativeUrls = true; diff --git a/test/browser/runner-relative-urls-spec.js b/test/browser/runner-relative-urls-spec.js new file mode 100644 index 000000000..ab576a003 --- /dev/null +++ b/test/browser/runner-relative-urls-spec.js @@ -0,0 +1,3 @@ +describe('less.js browser test - relative url\'s', function() { + testLessEqualsInDocument(); +}); diff --git a/test/browser/runner-rootpath-relative-options.js b/test/browser/runner-rootpath-relative-options.js index 0372bc61a..da32aa49b 100644 --- a/test/browser/runner-rootpath-relative-options.js +++ b/test/browser/runner-rootpath-relative-options.js @@ -1,4 +1,4 @@ var less = {logLevel: 4, errorReporting: 'console'}; less.rootpath = 'https://www.github.com/cloudhead/less.js/'; -less.rewriteUrls = 'all'; +less.relativeUrls = true; diff --git a/test/browser/runner-rootpath-relative-spec.js b/test/browser/runner-rootpath-relative-spec.js index c2305831b..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 rewrite urls', 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(); +}); From 2e73a021e698c4033f224a6abff94da90f6c9797 Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Tue, 26 Jun 2018 14:01:23 +0200 Subject: [PATCH 08/10] Improve tests - Remove redundant tests - Add rootpath-rewrite-urls-all test - Add rootpath-rewrite-urls-local test --- .../css/rewrite-urls-all/rewrite-urls-all.css | 24 +++++++------------ .../rewrite-urls-local/rewrite-urls-local.css | 24 +++++++------------ .../rootpath-rewrite-urls-all.css | 17 +++++++++++++ .../rootpath-rewrite-urls-local.css | 17 +++++++++++++ test/index.js | 2 ++ test/less/rewrite-urls-all/folder/file.less | 12 +++++----- .../rewrite-urls-all/rewrite-urls-all.less | 12 +++------- test/less/rewrite-urls-local/folder/file.less | 12 +++++----- .../rewrite-urls-local.less | 12 +++------- .../folder/file.less | 8 +++++++ .../rootpath-rewrite-urls-all.less | 11 +++++++++ .../folder/file.less | 8 +++++++ .../rootpath-rewrite-urls-local.less | 11 +++++++++ 13 files changed, 110 insertions(+), 60 deletions(-) create mode 100644 test/css/rootpath-rewrite-urls-all/rootpath-rewrite-urls-all.css create mode 100644 test/css/rootpath-rewrite-urls-local/rootpath-rewrite-urls-local.css create mode 100644 test/less/rootpath-rewrite-urls-all/folder/file.less create mode 100644 test/less/rootpath-rewrite-urls-all/rootpath-rewrite-urls-all.less create mode 100644 test/less/rootpath-rewrite-urls-local/folder/file.less create mode 100644 test/less/rootpath-rewrite-urls-local/rootpath-rewrite-urls-local.less diff --git a/test/css/rewrite-urls-all/rewrite-urls-all.css b/test/css/rewrite-urls-all/rewrite-urls-all.css index 2082bdcd3..c3d115dfb 100644 --- a/test/css/rewrite-urls-all/rewrite-urls-all.css +++ b/test/css/rewrite-urls-all/rewrite-urls-all.css @@ -1,23 +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); + 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('./relative/path'); - background-image: url(../relative/path); 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("./path"); + background-image: url("./"); background-image: url("module"); background-image: url("module/path"); - background-image: url(module/relative/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 index 99c287d40..b6ea2801d 100644 --- a/test/css/rewrite-urls-local/rewrite-urls-local.css +++ b/test/css/rewrite-urls-local/rewrite-urls-local.css @@ -1,23 +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); + 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('./relative/path'); - background-image: url(../relative/path); 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("./path"); + background-image: url("./"); background-image: url("module"); background-image: url("module/path"); - background-image: url(module/relative/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/index.js b/test/index.js index 06c4e26f1..2cdd57b54 100644 --- a/test/index.js +++ b/test/index.js @@ -50,6 +50,8 @@ var testMap = [ [{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 index 77495908e..7ab3847ed 100644 --- a/test/less/rewrite-urls-all/folder/file.less +++ b/test/less/rewrite-urls-all/folder/file.less @@ -1,8 +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); + 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 index 0959612ba..aae6d610f 100644 --- a/test/less/rewrite-urls-all/rewrite-urls-all.less +++ b/test/less/rewrite-urls-all/rewrite-urls-all.less @@ -1,17 +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("../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("./relative/../path"); + background-image: url("./relative/../path/.."); background-image: url("module"); background-image: url("module/path"); - background-image: url(module/path/../relative/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 index 77495908e..7ab3847ed 100644 --- a/test/less/rewrite-urls-local/folder/file.less +++ b/test/less/rewrite-urls-local/folder/file.less @@ -1,8 +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); + 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 index 8ea28d3ae..fb9a40e50 100644 --- a/test/less/rewrite-urls-local/rewrite-urls-local.less +++ b/test/less/rewrite-urls-local/rewrite-urls-local.less @@ -1,17 +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("../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("./relative/../path"); + background-image: url("./relative/../path/.."); background-image: url("module"); background-image: url("module/path"); - background-image: url(module/path/../relative/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"); +} From 2a4dfec7c33a02d4e9e87b77fa1df05cb6d6bb30 Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Tue, 26 Jun 2018 14:29:39 +0200 Subject: [PATCH 09/10] Fix typo in unknown argument warning --- bin/lessc | 4 ++-- lib/less-rhino/index.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/lessc b/bin/lessc index 380aa1e90..121e36209 100755 --- a/bin/lessc +++ b/bin/lessc @@ -483,12 +483,12 @@ function processPluginQueue() { case 'rewrite-urls': if (match[2] === 'all' || match[2] === 'local') { options.rewriteUrls = match[2]; - } if (match[2] === 'off') { + } else if (match[2] === 'off') { options.rewriteUrls = false; } else if (!match[2]) { options.rewriteUrls = 'all'; } else { - console.error('Unkown rewrite-urls argument ' + match[2]); + console.error('Unknown rewrite-urls argument ' + match[2]); continueProcessing = false; process.exitCode = 1; } diff --git a/lib/less-rhino/index.js b/lib/less-rhino/index.js index 65ae6cab1..b519a966e 100644 --- a/lib/less-rhino/index.js +++ b/lib/less-rhino/index.js @@ -320,7 +320,7 @@ function writeFile(filename, content) { } else if (!match[2]) { options.rewriteUrls = 'all'; } else { - print('Unkown rewrite-urls argument ' + match[2]); + print('Unknown rewrite-urls argument ' + match[2]); continueProcessing = false; currentErrorcode = 1; } From e0b7a6bd3f90b4ef2a30d7e41388a1baf40a8d26 Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Tue, 26 Jun 2018 15:25:58 +0200 Subject: [PATCH 10/10] Revert old tests to deprecated relativeUrls option again --- test/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/index.js b/test/index.js index 2cdd57b54..9e5c8f28f 100644 --- a/test/index.js +++ b/test/index.js @@ -9,7 +9,8 @@ lessTester.prepBomTest(); var testMap = [ [{ strictMath: false, - rewriteUrls: 'all', + // 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,7 +30,8 @@ var testMap = [ function(name) { return name + '-mediaquery'; }], [{strictMath: true, dumpLineNumbers: 'all'}, 'debug/', null, function(name) { return name + '-all'; }], - [{strictMath: true, rewriteUrls: false, rootpath: 'folder (1)/'}, 'static-urls/'], + // 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/'], [{}, 'legacy/'],