mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-31 07:32:59 +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:
		
							
								
								
									
										16
									
								
								boot/boot.js
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								boot/boot.js
									
									
									
									
									
								
							| @@ -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}; | 	$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. | Given an extension, get the correct encoding for that file. | ||||||
| defaults to utf8 | defaults to utf8 | ||||||
| */ | */ | ||||||
| $tw.utils.getTypeEncoding = function(ext) { | $tw.utils.getTypeEncoding = function(ext) { | ||||||
| 	var extensionInfo = $tw.config.fileExtensionInfo[ext], | 	var extensionInfo = $tw.util.getFileExtensionInfo(ext), | ||||||
| 		type = extensionInfo ? extensionInfo.type : null, | 		type = extensionInfo ? extensionInfo.type : null, | ||||||
| 		typeInfo = type ? $tw.config.contentTypeInfo[type] : null; | 		typeInfo = type ? $tw.config.contentTypeInfo[type] : null; | ||||||
| 	return typeInfo ? typeInfo.encoding : "utf8"; | 	return typeInfo ? typeInfo.encoding : "utf8"; | ||||||
| @@ -1137,9 +1145,9 @@ $tw.Wiki.prototype.deserializeTiddlers = function(type,text,srcFields) { | |||||||
| 	srcFields = srcFields || Object.create(null); | 	srcFields = srcFields || Object.create(null); | ||||||
| 	var deserializer = $tw.Wiki.tiddlerDeserializerModules[type], | 	var deserializer = $tw.Wiki.tiddlerDeserializerModules[type], | ||||||
| 		fields = Object.create(null); | 		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 | 		// 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]; | 		deserializer = $tw.Wiki.tiddlerDeserializerModules[type]; | ||||||
| 	} | 	} | ||||||
| 	if(!deserializer && $tw.config.contentTypeInfo[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) { | $tw.loadTiddlersFromFile = function(filepath,fields) { | ||||||
| 	var ext = path.extname(filepath), | 	var ext = path.extname(filepath), | ||||||
| 		extensionInfo = $tw.config.fileExtensionInfo[ext], | 		extensionInfo = $tw.utils.getFileExtensionInfo(ext), | ||||||
| 		type = extensionInfo ? extensionInfo.type : null, | 		type = extensionInfo ? extensionInfo.type : null, | ||||||
| 		typeInfo = type ? $tw.config.contentTypeInfo[type] : null, | 		typeInfo = type ? $tw.config.contentTypeInfo[type] : null, | ||||||
| 		data = fs.readFileSync(filepath,typeInfo ? typeInfo.encoding : "utf8"), | 		data = fs.readFileSync(filepath,typeInfo ? typeInfo.encoding : "utf8"), | ||||||
|   | |||||||
| @@ -761,8 +761,8 @@ exports.old_parseText = function(type,text,options) { | |||||||
| 	options = options || {}; | 	options = options || {}; | ||||||
| 	// Select a parser | 	// Select a parser | ||||||
| 	var Parser = $tw.Wiki.parsers[type]; | 	var Parser = $tw.Wiki.parsers[type]; | ||||||
| 	if(!Parser && $tw.config.fileExtensionInfo[type]) { | 	if(!Parser && $tw.utils.getFileExtensionInfo(type)) { | ||||||
| 		Parser = $tw.Wiki.parsers[$tw.config.fileExtensionInfo[type].type]; | 		Parser = $tw.Wiki.parsers[$tw.utils.getFileExtensionInfo(type).type]; | ||||||
| 	} | 	} | ||||||
| 	if(!Parser) { | 	if(!Parser) { | ||||||
| 		Parser = $tw.Wiki.parsers[options.defaultType || "text/vnd.tiddlywiki"]; | 		Parser = $tw.Wiki.parsers[options.defaultType || "text/vnd.tiddlywiki"]; | ||||||
| @@ -1104,7 +1104,7 @@ exports.readFile = function(file,callback) { | |||||||
| 	if(type === "" || !type) { | 	if(type === "" || !type) { | ||||||
| 		var dotPos = file.name.lastIndexOf("."); | 		var dotPos = file.name.lastIndexOf("."); | ||||||
| 		if(dotPos !== -1) { | 		if(dotPos !== -1) { | ||||||
| 			var fileExtensionInfo = $tw.config.fileExtensionInfo[file.name.substr(dotPos)]; | 			var fileExtensionInfo = $tw.utils.getFileExtensionInfo(file.name.substr(dotPos)); | ||||||
| 			if(fileExtensionInfo) { | 			if(fileExtensionInfo) { | ||||||
| 				type = fileExtensionInfo.type; | 				type = fileExtensionInfo.type; | ||||||
| 			} | 			} | ||||||
|   | |||||||
| @@ -38,7 +38,7 @@ exports["text/vnd.tiddlywiki2-recipe"] = function(text,fields) { | |||||||
| 		}, | 		}, | ||||||
| 		loadTiddlersFromFile = function(sourcePath,prefix) { | 		loadTiddlersFromFile = function(sourcePath,prefix) { | ||||||
| 			var ext = path.extname(sourcePath), | 			var ext = path.extname(sourcePath), | ||||||
| 				extensionInfo = $tw.config.fileExtensionInfo[ext], | 				extensionInfo = $tw.utils.getFileExtensionInfo(ext), | ||||||
| 				typeInfo = extensionInfo ? $tw.config.contentTypeInfo[extensionInfo.type] : null, | 				typeInfo = extensionInfo ? $tw.config.contentTypeInfo[extensionInfo.type] : null, | ||||||
| 				data = fs.readFileSync(sourcePath,typeInfo ? typeInfo.encoding : "utf8"), | 				data = fs.readFileSync(sourcePath,typeInfo ? typeInfo.encoding : "utf8"), | ||||||
| 				fields = {title: sourcePath}, | 				fields = {title: sourcePath}, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jim Lehmer
					Jim Lehmer