mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-29 21:09:56 +00:00
Adds $tw.utils.decodeURISafe and $tw.utils.decodeURIComponentSafe (#5999)
* call self.displayError
* Revert "call self.displayError"
This reverts commit 5d599aa979
.
* fixes decodeURI & decodeURIComponent
This commit is contained in:
parent
a67b1b8bb5
commit
33eef0202d
@ -1885,13 +1885,13 @@ $tw.loadTiddlersFromSpecification = function(filepath,excludeRegExp) {
|
|||||||
value = path.basename(filename);
|
value = path.basename(filename);
|
||||||
break;
|
break;
|
||||||
case "filename-uri-decoded":
|
case "filename-uri-decoded":
|
||||||
value = decodeURIComponent(path.basename(filename));
|
value = $tw.utils.decodeURIComponentSafe(path.basename(filename));
|
||||||
break;
|
break;
|
||||||
case "basename":
|
case "basename":
|
||||||
value = path.basename(filename,path.extname(filename));
|
value = path.basename(filename,path.extname(filename));
|
||||||
break;
|
break;
|
||||||
case "basename-uri-decoded":
|
case "basename-uri-decoded":
|
||||||
value = decodeURIComponent(path.basename(filename,path.extname(filename)));
|
value = $tw.utils.decodeURIComponentSafe(path.basename(filename,path.extname(filename)));
|
||||||
break;
|
break;
|
||||||
case "extname":
|
case "extname":
|
||||||
value = path.extname(filename);
|
value = path.extname(filename);
|
||||||
|
@ -19,12 +19,7 @@ Export our filter functions
|
|||||||
exports.decodeuricomponent = function(source,operator,options) {
|
exports.decodeuricomponent = function(source,operator,options) {
|
||||||
var results = [];
|
var results = [];
|
||||||
source(function(tiddler,title) {
|
source(function(tiddler,title) {
|
||||||
var value = title;
|
results.push($tw.utils.decodeURIComponentSafe(title));
|
||||||
try {
|
|
||||||
value = decodeURIComponent(title);
|
|
||||||
} catch(e) {
|
|
||||||
}
|
|
||||||
results.push(value);
|
|
||||||
});
|
});
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
@ -40,12 +35,7 @@ exports.encodeuricomponent = function(source,operator,options) {
|
|||||||
exports.decodeuri = function(source,operator,options) {
|
exports.decodeuri = function(source,operator,options) {
|
||||||
var results = [];
|
var results = [];
|
||||||
source(function(tiddler,title) {
|
source(function(tiddler,title) {
|
||||||
var value = title;
|
results.push($tw.utils.decodeURISafe(title));
|
||||||
try {
|
|
||||||
value = decodeURI(title);
|
|
||||||
} catch(e) {
|
|
||||||
}
|
|
||||||
results.push(value);
|
|
||||||
});
|
});
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
@ -42,7 +42,7 @@ AndTidWiki.prototype.save = function(text,method,callback,options) {
|
|||||||
window.twi.saveWiki(text);
|
window.twi.saveWiki(text);
|
||||||
} else {
|
} else {
|
||||||
// Get the pathname of this document
|
// Get the pathname of this document
|
||||||
var pathname = decodeURIComponent(document.location.toString().split("#")[0]);
|
var pathname = $tw.utils.decodeURIComponentSafe(document.location.toString().split("#")[0]);
|
||||||
// Strip the file://
|
// Strip the file://
|
||||||
if(pathname.indexOf("file://") === 0) {
|
if(pathname.indexOf("file://") === 0) {
|
||||||
pathname = pathname.substr(7);
|
pathname = pathname.substr(7);
|
||||||
|
@ -26,7 +26,7 @@ DownloadSaver.prototype.save = function(text,method,callback,options) {
|
|||||||
var p = document.location.pathname.lastIndexOf("/");
|
var p = document.location.pathname.lastIndexOf("/");
|
||||||
if(p !== -1) {
|
if(p !== -1) {
|
||||||
// We decode the pathname because document.location is URL encoded by the browser
|
// We decode the pathname because document.location is URL encoded by the browser
|
||||||
filename = decodeURIComponent(document.location.pathname.substr(p+1));
|
filename = $tw.utils.decodeURIComponentSafe(document.location.pathname.substr(p+1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!filename) {
|
if(!filename) {
|
||||||
|
@ -43,7 +43,7 @@ TiddlyFoxSaver.prototype.save = function(text,method,callback) {
|
|||||||
}
|
}
|
||||||
// Create the message element and put it in the message box
|
// Create the message element and put it in the message box
|
||||||
var message = document.createElement("div");
|
var message = document.createElement("div");
|
||||||
message.setAttribute("data-tiddlyfox-path",decodeURIComponent(pathname));
|
message.setAttribute("data-tiddlyfox-path",$tw.utils.decodeURIComponentSafe(pathname));
|
||||||
message.setAttribute("data-tiddlyfox-content",text);
|
message.setAttribute("data-tiddlyfox-content",text);
|
||||||
messageBox.appendChild(message);
|
messageBox.appendChild(message);
|
||||||
// Add an event handler for when the file has been saved
|
// Add an event handler for when the file has been saved
|
||||||
|
@ -21,7 +21,7 @@ TWEditSaver.prototype.save = function(text,method,callback) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Get the pathname of this document
|
// Get the pathname of this document
|
||||||
var pathname = decodeURIComponent(document.location.pathname);
|
var pathname = $tw.utils.decodeURIComponentSafe(document.location.pathname);
|
||||||
// Strip any query or location part
|
// Strip any query or location part
|
||||||
var p = pathname.indexOf("?");
|
var p = pathname.indexOf("?");
|
||||||
if(p !== -1) {
|
if(p !== -1) {
|
||||||
|
@ -17,7 +17,7 @@ exports.method = "DELETE";
|
|||||||
exports.path = /^\/bags\/default\/tiddlers\/(.+)$/;
|
exports.path = /^\/bags\/default\/tiddlers\/(.+)$/;
|
||||||
|
|
||||||
exports.handler = function(request,response,state) {
|
exports.handler = function(request,response,state) {
|
||||||
var title = decodeURIComponent(state.params[0]);
|
var title = $tw.utils.decodeURIComponentSafe(state.params[0]);
|
||||||
state.wiki.deleteTiddler(title);
|
state.wiki.deleteTiddler(title);
|
||||||
response.writeHead(204, "OK", {
|
response.writeHead(204, "OK", {
|
||||||
"Content-Type": "text/plain"
|
"Content-Type": "text/plain"
|
||||||
|
@ -20,7 +20,7 @@ exports.handler = function(request,response,state) {
|
|||||||
var path = require("path"),
|
var path = require("path"),
|
||||||
fs = require("fs"),
|
fs = require("fs"),
|
||||||
util = require("util"),
|
util = require("util"),
|
||||||
suppliedFilename = decodeURIComponent(state.params[0]),
|
suppliedFilename = $tw.utils.decodeURIComponentSafe(state.params[0]),
|
||||||
baseFilename = path.resolve(state.boot.wikiPath,"files"),
|
baseFilename = path.resolve(state.boot.wikiPath,"files"),
|
||||||
filename = path.resolve(baseFilename,suppliedFilename),
|
filename = path.resolve(baseFilename,suppliedFilename),
|
||||||
extension = path.extname(filename);
|
extension = path.extname(filename);
|
||||||
|
@ -17,7 +17,7 @@ exports.method = "GET";
|
|||||||
exports.path = /^\/([^\/]+)$/;
|
exports.path = /^\/([^\/]+)$/;
|
||||||
|
|
||||||
exports.handler = function(request,response,state) {
|
exports.handler = function(request,response,state) {
|
||||||
var title = decodeURIComponent(state.params[0]),
|
var title = $tw.utils.decodeURIComponentSafe(state.params[0]),
|
||||||
tiddler = state.wiki.getTiddler(title);
|
tiddler = state.wiki.getTiddler(title);
|
||||||
if(tiddler) {
|
if(tiddler) {
|
||||||
var renderType = tiddler.getFieldString("_render_type"),
|
var renderType = tiddler.getFieldString("_render_type"),
|
||||||
|
@ -17,7 +17,7 @@ exports.method = "GET";
|
|||||||
exports.path = /^\/recipes\/default\/tiddlers\/(.+)$/;
|
exports.path = /^\/recipes\/default\/tiddlers\/(.+)$/;
|
||||||
|
|
||||||
exports.handler = function(request,response,state) {
|
exports.handler = function(request,response,state) {
|
||||||
var title = decodeURIComponent(state.params[0]),
|
var title = $tw.utils.decodeURIComponentSafe(state.params[0]),
|
||||||
tiddler = state.wiki.getTiddler(title),
|
tiddler = state.wiki.getTiddler(title),
|
||||||
tiddlerFields = {},
|
tiddlerFields = {},
|
||||||
knownFields = [
|
knownFields = [
|
||||||
|
@ -17,7 +17,7 @@ exports.method = "PUT";
|
|||||||
exports.path = /^\/recipes\/default\/tiddlers\/(.+)$/;
|
exports.path = /^\/recipes\/default\/tiddlers\/(.+)$/;
|
||||||
|
|
||||||
exports.handler = function(request,response,state) {
|
exports.handler = function(request,response,state) {
|
||||||
var title = decodeURIComponent(state.params[0]),
|
var title = $tw.utils.decodeURIComponentSafe(state.params[0]),
|
||||||
fields = JSON.parse(state.data);
|
fields = JSON.parse(state.data);
|
||||||
// Pull up any subfields in the `fields` object
|
// Pull up any subfields in the `fields` object
|
||||||
if(fields.fields) {
|
if(fields.fields) {
|
||||||
|
@ -120,10 +120,10 @@ function openStartupTiddlers(options) {
|
|||||||
var hash = $tw.locationHash.substr(1),
|
var hash = $tw.locationHash.substr(1),
|
||||||
split = hash.indexOf(":");
|
split = hash.indexOf(":");
|
||||||
if(split === -1) {
|
if(split === -1) {
|
||||||
target = decodeURIComponent(hash.trim());
|
target = $tw.utils.decodeURIComponentSafe(hash.trim());
|
||||||
} else {
|
} else {
|
||||||
target = decodeURIComponent(hash.substr(0,split).trim());
|
target = $tw.utils.decodeURIComponentSafe(hash.substr(0,split).trim());
|
||||||
storyFilter = decodeURIComponent(hash.substr(split + 1).trim());
|
storyFilter = $tw.utils.decodeURIComponentSafe(hash.substr(split + 1).trim());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If the story wasn't specified use the current tiddlers or a blank story
|
// If the story wasn't specified use the current tiddlers or a blank story
|
||||||
|
@ -164,7 +164,7 @@ var importDataTypes = [
|
|||||||
}},
|
}},
|
||||||
{type: "URL", IECompatible: true, toTiddlerFieldsArray: function(data,fallbackTitle) {
|
{type: "URL", IECompatible: true, toTiddlerFieldsArray: function(data,fallbackTitle) {
|
||||||
// Check for tiddler data URI
|
// Check for tiddler data URI
|
||||||
var match = decodeURIComponent(data).match(/^data\:text\/vnd\.tiddler,(.*)/i);
|
var match = $tw.utils.decodeURIComponentSafe(data).match(/^data\:text\/vnd\.tiddler,(.*)/i);
|
||||||
if(match) {
|
if(match) {
|
||||||
return parseJSONTiddlers(match[1],fallbackTitle);
|
return parseJSONTiddlers(match[1],fallbackTitle);
|
||||||
} else {
|
} else {
|
||||||
@ -173,7 +173,7 @@ var importDataTypes = [
|
|||||||
}},
|
}},
|
||||||
{type: "text/x-moz-url", IECompatible: false, toTiddlerFieldsArray: function(data,fallbackTitle) {
|
{type: "text/x-moz-url", IECompatible: false, toTiddlerFieldsArray: function(data,fallbackTitle) {
|
||||||
// Check for tiddler data URI
|
// Check for tiddler data URI
|
||||||
var match = decodeURIComponent(data).match(/^data\:text\/vnd\.tiddler,(.*)/i);
|
var match = $tw.utils.decodeURIComponentSafe(data).match(/^data\:text\/vnd\.tiddler,(.*)/i);
|
||||||
if(match) {
|
if(match) {
|
||||||
return parseJSONTiddlers(match[1],fallbackTitle);
|
return parseJSONTiddlers(match[1],fallbackTitle);
|
||||||
} else {
|
} else {
|
||||||
|
@ -969,4 +969,22 @@ exports.makeCompareFunction = function(type,options) {
|
|||||||
return (types[type] || types[options.defaultType] || types.number);
|
return (types[type] || types[options.defaultType] || types.number);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.decodeURIComponentSafe = function(str) {
|
||||||
|
var value = str;
|
||||||
|
try {
|
||||||
|
value = decodeURIComponent(str);
|
||||||
|
} catch(e) {
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.decodeURISafe = function(str) {
|
||||||
|
var value = str;
|
||||||
|
try {
|
||||||
|
value = decodeURI(str);
|
||||||
|
} catch(e) {
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -149,7 +149,7 @@ function convertNodes(remarkableTree, isStartOfInline) {
|
|||||||
out.push({
|
out.push({
|
||||||
type: "link",
|
type: "link",
|
||||||
attributes: {
|
attributes: {
|
||||||
to: { type: "string", value: decodeURI(currentNode.href.substr(1)) }
|
to: { type: "string", value: $tw.utils.decodeURISafe(currentNode.href.substr(1)) }
|
||||||
},
|
},
|
||||||
children: children
|
children: children
|
||||||
});
|
});
|
||||||
@ -180,7 +180,7 @@ function convertNodes(remarkableTree, isStartOfInline) {
|
|||||||
type: "image",
|
type: "image",
|
||||||
attributes: {
|
attributes: {
|
||||||
tooltip: { type: "string", value: currentNode.alt },
|
tooltip: { type: "string", value: currentNode.alt },
|
||||||
source: { type: "string", value: decodeURIComponent(currentNode.src) }
|
source: { type: "string", value: $tw.utils.decodeURIComponentSafe(currentNode.src) }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@ -17,7 +17,7 @@ var rawHash = document.location.hash.substring(1);
|
|||||||
if(rawHash.charAt(0) === "#") {
|
if(rawHash.charAt(0) === "#") {
|
||||||
var hash;
|
var hash;
|
||||||
try{
|
try{
|
||||||
hash = decodeURIComponent(rawHash.substring(1));
|
hash = $tw.utils.decodeURIComponentSafe(rawHash.substring(1));
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
console.log("Share plugin: Error decoding location hash",ex);
|
console.log("Share plugin: Error decoding location hash",ex);
|
||||||
}
|
}
|
||||||
|
@ -346,8 +346,8 @@ TiddlyWebAdaptor.prototype.parseEtag = function(etag) {
|
|||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
bag: decodeURIComponent(etag.substring(1,firstSlash)),
|
bag: $tw.utils.decodeURIComponentSafe(etag.substring(1,firstSlash)),
|
||||||
title: decodeURIComponent(etag.substring(firstSlash + 1,lastSlash)),
|
title: $tw.utils.decodeURIComponentSafe(etag.substring(firstSlash + 1,lastSlash)),
|
||||||
revision: etag.substring(lastSlash + 1,colon)
|
revision: etag.substring(lastSlash + 1,colon)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user