[Pkg-javascript-commits] [less.js] 08/25: Fragment handling in data-uri function 1959

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


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

js pushed a commit to annotated tag v1.7.5
in repository less.js.

commit 0f8bd724f8bee7574c52fe744883956a290ccc5c
Author: jurcovicovam <meri at meri.org>
Date:   Sun Aug 3 13:20:02 2014 +0200

    Fragment handling in data-uri function 1959
    
    The change removes #fragment from filePath before readig the file and adds
    it back to the end of the generated uri.
---
 lib/less/functions.js | 9 ++++++++-
 test/css/urls.css     | 1 +
 test/less/urls.less   | 3 ++-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/lib/less/functions.js b/lib/less/functions.js
index 16edc18..f99264c 100644
--- a/lib/less/functions.js
+++ b/lib/less/functions.js
@@ -422,6 +422,13 @@ tree.functions = {
             filePath = mimetype;
         }
 
+        var fragmentStart = filePath.indexOf('#');
+        var fragment = '';
+        if (fragmentStart!==-1) {
+            fragment = filePath.slice(fragmentStart);
+            filePath = filePath.slice(0, fragmentStart);
+        }
+
         if (this.env.isPathRelative(filePath)) {
             if (this.currentFileInfo.relativeUrls) {
                 filePath = path.join(this.currentFileInfo.currentDirectory, filePath);
@@ -470,7 +477,7 @@ tree.functions = {
         buf = useBase64 ? buf.toString('base64')
                         : encodeURIComponent(buf);
 
-        var uri = "\"data:" + mimetype + ',' + buf + "\"";
+        var uri = "\"data:" + mimetype + ',' + buf + fragment + "\"";
         return new(tree.URL)(new(tree.Anonymous)(uri));
     },
 
diff --git a/test/css/urls.css b/test/css/urls.css
index 27a7050..1604251 100644
--- a/test/css/urls.css
+++ b/test/css/urls.css
@@ -53,6 +53,7 @@
 }
 #data-uri {
   uri: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
+  uri-fragment: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==#fragment");
 }
 #data-uri-guess {
   uri: url("data:image/jpeg;base64,bm90IGFjdHVhbGx5IGEganBlZyBmaWxlCg==");
diff --git a/test/less/urls.less b/test/less/urls.less
index bd7c57a..9569415 100644
--- a/test/less/urls.less
+++ b/test/less/urls.less
@@ -42,6 +42,7 @@
 
 #data-uri {
   uri: data-uri('image/jpeg;base64', '../data/image.jpg');
+  uri-fragment: data-uri('image/jpeg;base64', '../data/image.jpg#fragment');
 }
 
 #data-uri-guess {
@@ -80,4 +81,4 @@
   src+: format('truetype');
   src+_: url('webfont.ttf');
   src+: url('webfont.svg#svgFontName') format('svg');
-}
\ No newline at end of file
+}

-- 
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