Skip to content

Commit

Permalink
Merge pull request #2136 from SomMeri/data-uri-1959
Browse files Browse the repository at this point in the history
Fragment handling in data-uri function 1959
  • Loading branch information
lukeapage committed Aug 14, 2014
2 parents 169bbad + 0f8bd72 commit 466bc39
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/less/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
},

Expand Down
1 change: 1 addition & 0 deletions test/css/urls.css
Original file line number Diff line number Diff line change
Expand Up @@ -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==");
Expand Down
3 changes: 2 additions & 1 deletion test/less/urls.less
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -80,4 +81,4 @@
src+: format('truetype');
src+_: url('webfont.ttf');
src+: url('webfont.svg#svgFontName') format('svg');
}
}

0 comments on commit 466bc39

Please sign in to comment.