Fix open/save window importing BibTeX files without UTF-8 BOM in auto mode -- just default to UTF-8

This commit is contained in:
Dan Stillman 2009-11-25 01:31:31 +00:00
parent 31943dfba7
commit 3b9f23baf3
3 changed files with 11 additions and 7 deletions

View file

@ -245,12 +245,14 @@ Zotero.File = new function(){
*/ */
function getCharsetFromFile(file, mimeType, callback, args){ function getCharsetFromFile(file, mimeType, callback, args){
if (!file || !file.exists()){ if (!file || !file.exists()){
return false; callback(false, args);
return;
} }
if (mimeType.substr(0, 5)!='text/' || if (mimeType.substr(0, 5) != 'text/' ||
!Zotero.MIME.hasInternalHandler(mimeType, this.getExtension(file))){ !Zotero.MIME.hasInternalHandler(mimeType, this.getExtension(file))) {
return false; callback(false, args);
return;
} }
var browser = Zotero.Browser.createHiddenBrowser(); var browser = Zotero.Browser.createHiddenBrowser();

View file

@ -79,7 +79,8 @@ Zotero.MIME = new function(){
var _externalTextExtensions = { var _externalTextExtensions = {
graffle: true, graffle: true,
mm: true, mm: true,
opml: true opml: true,
bib: true
}; };
@ -324,7 +325,7 @@ Zotero.MIME = new function(){
function hasNativeHandler(mimeType, ext) { function hasNativeHandler(mimeType, ext) {
if (mimeType.match(/^text\//)) { if (mimeType.match(/^text\//)) {
if (isExternalTextExtension(ext)){ if (isExternalTextExtension(ext)){
Zotero.debug('text file has extension that should be handled externally'); Zotero.debug(mimeType + " file has extension '" + ext + "' that should be handled externally");
return false; return false;
} }
return true; return true;

View file

@ -1799,7 +1799,8 @@ Zotero.Translate.prototype._importSniffCharacterSet = function(callback) {
var me = this; var me = this;
Zotero.File.getCharsetFromFile(this.location, "text/plain", Zotero.File.getCharsetFromFile(this.location, "text/plain",
function(charset) { function(charset) {
me._charset = charset; // Default to UTF-8 if no charset available
me._charset = charset ? charset : "UTF-8";
me._importDoneSniffing(charset); me._importDoneSniffing(charset);
}); });
} else { } else {