[Pkg-javascript-commits] [less.js] 07/38: Improve url check to be more robust, fix tests

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:27:24 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag v2.2.0
in repository less.js.

commit 19b606b4393815054cab344f44abf833850ae0a4
Author: Matthew Smith <mtscout6 at gmail.com>
Date:   Wed Dec 31 13:09:02 2014 -0700

    Improve url check to be more robust, fix tests
    
    I figured out that the test would still fail if I call the import in the
    urls.less file. That way I don't need to figure out all the setup
    required to test this bug.
    
    - #2360
---
 lib/less/contexts.js                                      |  7 +++++++
 lib/less/tree/url.js                                      |  6 +++++-
 test/browser/css/urls.css                                 |  3 +++
 .../nested-gradient-with-svg-gradient/mixin-consumer.less |  5 +++++
 .../svg-gradient-mixin.less                               | 15 +++++++++++++++
 test/browser/less/urls.less                               |  1 +
 test/css/nested-mixin-with-svg-gradient.css               |  3 ---
 test/css/urls.css                                         |  3 +++
 test/less/nested-mixin-with-svg-gradient.less             |  1 -
 test/less/urls.less                                       |  2 ++
 10 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/lib/less/contexts.js b/lib/less/contexts.js
index 5c0ef6d..e21706e 100644
--- a/lib/less/contexts.js
+++ b/lib/less/contexts.js
@@ -79,6 +79,13 @@ contexts.Eval.prototype.isPathRelative = function (path) {
     return !/^(?:[a-z-]+:|\/)/i.test(path);
 };
 
+contexts.Eval.prototype.isPathExternal = function (path) {
+  // An URL is external if
+  // 1. it's a Data Url
+  // 2. it's an absolute url or and protocol-relative
+  return /^data:|^(https?:)?\/\/|^[\{\}\[\]#*;,'§\$%&\(=?`´\^°<>]/.test(path);
+};
+
 contexts.Eval.prototype.normalizePath = function( path ) {
     var
       segments = path.split("/").reverse(),
diff --git a/lib/less/tree/url.js b/lib/less/tree/url.js
index a58a577..71f39ac 100644
--- a/lib/less/tree/url.js
+++ b/lib/less/tree/url.js
@@ -23,7 +23,11 @@ URL.prototype.eval = function (context) {
     if (!this.isEvald) {
         // Add the base path if the URL is relative
         rootpath = this.currentFileInfo && this.currentFileInfo.rootpath;
-        if (rootpath && typeof val.value === "string" && !/^'?data:/.test(val.value) && context.isPathRelative(val.value)) {
+        if (rootpath &&
+            typeof val.value === "string" &&
+            !context.isPathExternal(val.value) &&
+            context.isPathRelative(val.value)) {
+
             if (!val.quote) {
                 rootpath = rootpath.replace(/[\(\)'"\s]/g, function(match) { return "\\"+match; });
             }
diff --git a/test/browser/css/urls.css b/test/browser/css/urls.css
index f55542e..98cc8a9 100644
--- a/test/browser/css/urls.css
+++ b/test/browser/css/urls.css
@@ -6,6 +6,9 @@
 .modify {
   my-url: url("http://localhost:8081/test/browser/less/b.png");
 }
+.gray-gradient {
+  background: url('data:image/svg+xml,<?xml version="1.0" ?><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="100%" viewBox="0 0 1 1" preserveAspectRatio="none"><linearGradient id="gradient" gradientUnits="userSpaceOnUse" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="0%" stop-color="#999999" stop-opacity="0"/><stop offset="60%" stop-color="#999999" stop-opacity="0.05"/><stop offset="70%" stop-color="#999999" stop-opacity="0.1"/><stop offset="73%" stop-color="#9 [...]
+}
 @font-face {
   src: url("/fonts/garamond-pro.ttf");
   src: local(Futura-Medium), url(http://localhost:8081/test/browser/less/fonts.svg#MyGeometricModern) format("svg");
diff --git a/test/browser/less/nested-gradient-with-svg-gradient/mixin-consumer.less b/test/browser/less/nested-gradient-with-svg-gradient/mixin-consumer.less
new file mode 100644
index 0000000..12bba2e
--- /dev/null
+++ b/test/browser/less/nested-gradient-with-svg-gradient/mixin-consumer.less
@@ -0,0 +1,5 @@
+ at import "svg-gradient-mixin.less";
+
+.gray-gradient {
+  .gradient-mixin(#999);
+}
diff --git a/test/browser/less/nested-gradient-with-svg-gradient/svg-gradient-mixin.less b/test/browser/less/nested-gradient-with-svg-gradient/svg-gradient-mixin.less
new file mode 100644
index 0000000..fad96ea
--- /dev/null
+++ b/test/browser/less/nested-gradient-with-svg-gradient/svg-gradient-mixin.less
@@ -0,0 +1,15 @@
+.gradient-mixin(@color) {
+  background: svg-gradient(to bottom,
+    fade(@color, 0%) 0%,
+    fade(@color, 5%) 60%,
+    fade(@color, 10%) 70%,
+    fade(@color, 15%) 73%,
+    fade(@color, 20%) 75%,
+    fade(@color, 25%) 80%,
+    fade(@color, 30%) 85%,
+    fade(@color, 35%) 88%,
+    fade(@color, 40%) 90%,
+    fade(@color, 45%) 95%,
+    fade(@color, 50%) 100%
+  );
+}
diff --git a/test/browser/less/urls.less b/test/browser/less/urls.less
index ec478fe..0578461 100644
--- a/test/browser/less/urls.less
+++ b/test/browser/less/urls.less
@@ -1,5 +1,6 @@
 @import "imports/urls.less";
 @import "http://localhost:8081/test/browser/less/imports/urls2.less";
+ at import "http://localhost:8081/test/browser/less/nested-gradient-with-svg-gradient/mixin-consumer.less";
 @font-face {
   src: url("/fonts/garamond-pro.ttf");
   src: local(Futura-Medium),
diff --git a/test/css/nested-mixin-with-svg-gradient.css b/test/css/nested-mixin-with-svg-gradient.css
deleted file mode 100644
index 59ab966..0000000
--- a/test/css/nested-mixin-with-svg-gradient.css
+++ /dev/null
@@ -1,3 +0,0 @@
-.gray-gradient {
-  background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2ZXJzaW9uPSIxLjEiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIHZpZXdCb3g9IjAgMCAxIDEiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPjxsaW5lYXJHcmFkaWVudCBpZD0iZ3JhZGllbnQiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIiB4MT0iMCUiIHkxPSIwJSIgeDI9IjAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzk5OTk5OSIgc3RvcC1vcGFjaXR5PSIwIi8+PHN0b3Agb2Zmc2V0PSI2MCUiIHN0b3AtY29sb3I9IiM5OTk [...]
-}
diff --git a/test/css/urls.css b/test/css/urls.css
index fac9b85..e84e5c9 100644
--- a/test/css/urls.css
+++ b/test/css/urls.css
@@ -1,6 +1,9 @@
 @import "css/background.css";
 @import "import/import-test-d.css";
 @import "file.css";
+.gray-gradient {
+  background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2ZXJzaW9uPSIxLjEiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIHZpZXdCb3g9IjAgMCAxIDEiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPjxsaW5lYXJHcmFkaWVudCBpZD0iZ3JhZGllbnQiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIiB4MT0iMCUiIHkxPSIwJSIgeDI9IjAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzk5OTk5OSIgc3RvcC1vcGFjaXR5PSIwIi8+PHN0b3Agb2Zmc2V0PSI2MCUiIHN0b3AtY29sb3I9IiM5OTk [...]
+}
 @font-face {
   src: url("/fonts/garamond-pro.ttf");
   src: local(Futura-Medium), url(fonts.svg#MyGeometricModern) format("svg");
diff --git a/test/less/nested-mixin-with-svg-gradient.less b/test/less/nested-mixin-with-svg-gradient.less
deleted file mode 100644
index 41eae43..0000000
--- a/test/less/nested-mixin-with-svg-gradient.less
+++ /dev/null
@@ -1 +0,0 @@
- at import "./nested-gradient-with-svg-gradient/mixin-consumer.less";
diff --git a/test/less/urls.less b/test/less/urls.less
index 73c807c..e166a89 100644
--- a/test/less/urls.less
+++ b/test/less/urls.less
@@ -1,3 +1,5 @@
+ at import "nested-gradient-with-svg-gradient/mixin-consumer.less";
+
 @font-face {
   src: url("/fonts/garamond-pro.ttf");
   src: local(Futura-Medium),

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git



More information about the Pkg-javascript-commits mailing list