Skip to content

Commit 2142717

Browse files
committed
Prepend BOM for UTF-8 XML and text/plain types
1 parent 24b303f commit 2142717

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

FileSaver.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* FileSaver.js
22
* A saveAs() FileSaver implementation.
3-
* 2015-01-04
3+
* 2015-03-04
44
*
55
* By Eli Grey, http://eligrey.com
66
* License: X11/MIT
@@ -135,6 +135,10 @@ var saveAs = saveAs
135135
revoke(object_url);
136136
return;
137137
}
138+
// prepend BOM for UTF-8 XML and text/plain types
139+
if (/^\s*(?:text\/(?:plain|xml)|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
140+
blob = new Blob(["\ufeff", blob], {type: blob.type});
141+
}
138142
// Object and web filesystem URLs have a problem saving in Google Chrome when
139143
// viewed in a tab, so I force save with application/octet-stream
140144
// http://code.google.com/p/chromium/issues/detail?id=91158

FileSaver.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)