[Pkg-javascript-commits] [less.js] 16/38: Fix data-uri to count characters not the size of the file.
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:27:25 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 f0780394fb51bb93f72c26478883441f26c5bcd7
Author: Luke Page <luke.a.page at gmail.com>
Date: Thu Jan 1 19:06:05 2015 +0000
Fix data-uri to count characters not the size of the file.
---
lib/less/functions/data-uri.js | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/lib/less/functions/data-uri.js b/lib/less/functions/data-uri.js
index 6f2d408..08ceb8e 100644
--- a/lib/less/functions/data-uri.js
+++ b/lib/less/functions/data-uri.js
@@ -54,20 +54,6 @@ module.exports = function(environment) {
return fallback(this, filePathNode || mimetypeNode);
}
var buf = fileSync.contents;
-
- // IE8 cannot handle a data-uri larger than 32KB. If this is exceeded
- // and the --ieCompat flag is enabled, return a normal url() instead.
- var DATA_URI_MAX_KB = 32,
- fileSizeInKB = parseInt((buf.length / 1024), 10);
- if (fileSizeInKB >= DATA_URI_MAX_KB) {
-
- if (this.context.ieCompat !== false) {
- logger.warn("Skipped data-uri embedding of " + filePath + " because its size (" + fileSizeInKB.toFixed(1) + "KB) exceeds IE8-safe " + DATA_URI_MAX_KB.toFixed(1) + "KB!");
-
- return fallback(this, filePathNode || mimetypeNode);
- }
- }
-
if (useBase64 && !environment.encodeBase64) {
return fallback(this, filePathNode);
}
@@ -75,6 +61,19 @@ module.exports = function(environment) {
buf = useBase64 ? environment.encodeBase64(buf) : encodeURIComponent(buf);
var uri = "data:" + mimetype + ',' + buf + fragment;
+
+ // IE8 cannot handle a data-uri larger than 32,768 characters. If this is exceeded
+ // and the --ieCompat flag is enabled, return a normal url() instead.
+ var DATA_URI_MAX = 32768;
+ if (uri.length >= DATA_URI_MAX) {
+
+ if (this.context.ieCompat !== false) {
+ logger.warn("Skipped data-uri embedding of " + filePath + " because its size (" + uri.length + " characters) exceeds IE8-safe " + DATA_URI_MAX + " characters!");
+
+ return fallback(this, filePathNode || mimetypeNode);
+ }
+ }
+
return new URL(new Quoted('"' + uri + '"', uri, false, this.index, this.currentFileInfo), this.index, this.currentFileInfo);
});
};
--
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