1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-10-27 21:57:39 +00:00

Make sure all "get" access to $tw.config.fileExtensionInfo goes through a $tw.utils.getFileExtensionInfo helper function that ensures the parameter is cast to lowercase. Fixes #1418.

This commit is contained in:
Jim Lehmer
2015-02-01 12:33:40 -06:00
parent 2db6cbed2d
commit 8cd0c2afcd
3 changed files with 16 additions and 8 deletions

View File

@@ -397,12 +397,20 @@ $tw.utils.registerFileType = function(type,encoding,extension,options) {
$tw.config.contentTypeInfo[type] = {encoding: encoding, extension: extension, flags: options.flags || [], deserializerType: options.deserializerType || type};
};
/*
Given an extension, always access the $tw.config.fileExtensionInfo
using a lowercase extension only.
*/
$tw.utils.getFileExtensionInfo = function(ext) {
return ext ? $tw.config.fileExtensionInfo[ext.toLowerCase()] : null;
}
/*
Given an extension, get the correct encoding for that file.
defaults to utf8
*/
$tw.utils.getTypeEncoding = function(ext) {
var extensionInfo = $tw.config.fileExtensionInfo[ext],
var extensionInfo = $tw.util.getFileExtensionInfo(ext),
type = extensionInfo ? extensionInfo.type : null,
typeInfo = type ? $tw.config.contentTypeInfo[type] : null;
return typeInfo ? typeInfo.encoding : "utf8";
@@ -1137,9 +1145,9 @@ $tw.Wiki.prototype.deserializeTiddlers = function(type,text,srcFields) {
srcFields = srcFields || Object.create(null);
var deserializer = $tw.Wiki.tiddlerDeserializerModules[type],
fields = Object.create(null);
if(!deserializer && $tw.config.fileExtensionInfo[type]) {
if(!deserializer && $tw.utils.getFileExtensionInfo(type)) {
// If we didn't find the serializer, try converting it from an extension to a content type
type = $tw.config.fileExtensionInfo[type].type;
type = $tw.utils.getFileExtensionInfo(type).type;
deserializer = $tw.Wiki.tiddlerDeserializerModules[type];
}
if(!deserializer && $tw.config.contentTypeInfo[type]) {
@@ -1386,7 +1394,7 @@ Load the tiddlers contained in a particular file (and optionally extract fields
*/
$tw.loadTiddlersFromFile = function(filepath,fields) {
var ext = path.extname(filepath),
extensionInfo = $tw.config.fileExtensionInfo[ext],
extensionInfo = $tw.utils.getFileExtensionInfo(ext),
type = extensionInfo ? extensionInfo.type : null,
typeInfo = type ? $tw.config.contentTypeInfo[type] : null,
data = fs.readFileSync(filepath,typeInfo ? typeInfo.encoding : "utf8"),