Merge pull request #2136 from SomMeri/data-uri-1959

Fragment handling in data-uri function 1959
This commit is contained in:
Luke Page
2014-08-14 17:13:25 +01:00
3 changed files with 11 additions and 2 deletions

View File

@@ -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));
},

View File

@@ -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==");

View File

@@ -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');
}
}