mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-19 10:49:43 +00:00
326ae61929
* Fix encodebase64 and decodebase64 filters The documentation for encodebase64 says that the input is treated as binary data, but in fact the input is being treated as text data, with an extra UTF-8 encoding step being performed first. Likewise, the decodebase64 documentation says that it outputs binary data, but in fact it will do a UTF-8 decoding step before producing output, which will in fact garble binary data. This commit changes the behavior of encodebase64 and decodebase64 to match what the documentation says they do. It also adds an optional `text` suffix to both filters to keep the current behavior. Finally, an optional `urlsafe` suffix is added to both filters to allow them to use the "URL-safe" variant of base64 (using `-` instead of `+` and `_` instead of `/`). * Try to fix failing test Turns out a little more than this is going to be needed. * Fix binary base64 encoding, including unit tests * Update base64 filter documentation * Can't use replaceAll, too new Have to use String.replace with a global regex instead * Replace uses of window.btoa() in rest of code Since window.btoa() is not available under Node.js, we'll replace all uses of it with the $tw.utils.base64encode() function that now works correctly for binary data. * Add link to UTF-8 glossary definition at MDN
121 lines
3.0 KiB
JavaScript
121 lines
3.0 KiB
JavaScript
/*\
|
|
title: $:/core/modules/filters/decodeuricomponent.js
|
|
type: application/javascript
|
|
module-type: filteroperator
|
|
|
|
Filter operator for applying decodeURIComponent() to each item.
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
/*
|
|
Export our filter functions
|
|
*/
|
|
|
|
exports.decodebase64 = function(source,operator,options) {
|
|
var results = [];
|
|
var binary = operator.suffixes && operator.suffixes.indexOf("binary") !== -1;
|
|
var urlsafe = operator.suffixes && operator.suffixes.indexOf("urlsafe") !== -1;
|
|
source(function(tiddler,title) {
|
|
results.push($tw.utils.base64Decode(title,binary,urlsafe));
|
|
});
|
|
return results;
|
|
};
|
|
|
|
exports.encodebase64 = function(source,operator,options) {
|
|
var results = [];
|
|
var binary = operator.suffixes && operator.suffixes.indexOf("binary") !== -1;
|
|
var urlsafe = operator.suffixes && operator.suffixes.indexOf("urlsafe") !== -1;
|
|
source(function(tiddler,title) {
|
|
results.push($tw.utils.base64Encode(title,binary,urlsafe));
|
|
});
|
|
return results;
|
|
};
|
|
|
|
exports.decodeuricomponent = function(source,operator,options) {
|
|
var results = [];
|
|
source(function(tiddler,title) {
|
|
results.push($tw.utils.decodeURIComponentSafe(title));
|
|
});
|
|
return results;
|
|
};
|
|
|
|
exports.encodeuricomponent = function(source,operator,options) {
|
|
var results = [];
|
|
source(function(tiddler,title) {
|
|
results.push($tw.utils.encodeURIComponentExtended(title));
|
|
});
|
|
return results;
|
|
};
|
|
|
|
exports.decodeuri = function(source,operator,options) {
|
|
var results = [];
|
|
source(function(tiddler,title) {
|
|
results.push($tw.utils.decodeURISafe(title));
|
|
});
|
|
return results;
|
|
};
|
|
|
|
exports.encodeuri = function(source,operator,options) {
|
|
var results = [];
|
|
source(function(tiddler,title) {
|
|
results.push(encodeURI(title));
|
|
});
|
|
return results;
|
|
};
|
|
|
|
exports.decodehtml = function(source,operator,options) {
|
|
var results = [];
|
|
source(function(tiddler,title) {
|
|
results.push($tw.utils.htmlDecode(title));
|
|
});
|
|
return results;
|
|
};
|
|
|
|
exports.encodehtml = function(source,operator,options) {
|
|
var results = [];
|
|
source(function(tiddler,title) {
|
|
results.push($tw.utils.htmlEncode(title));
|
|
});
|
|
return results;
|
|
};
|
|
|
|
exports.stringify = function(source,operator,options) {
|
|
var results = [];
|
|
source(function(tiddler,title) {
|
|
results.push($tw.utils.stringify(title,(operator.suffix === "rawunicode")));
|
|
});
|
|
return results;
|
|
};
|
|
|
|
exports.jsonstringify = function(source,operator,options) {
|
|
var results = [];
|
|
source(function(tiddler,title) {
|
|
results.push($tw.utils.jsonStringify(title,(operator.suffix === "rawunicode")));
|
|
});
|
|
return results;
|
|
};
|
|
|
|
exports.escaperegexp = function(source,operator,options) {
|
|
var results = [];
|
|
source(function(tiddler,title) {
|
|
results.push($tw.utils.escapeRegExp(title));
|
|
});
|
|
return results;
|
|
};
|
|
|
|
exports.escapecss = function(source,operator,options) {
|
|
var results = [];
|
|
source(function(tiddler,title) {
|
|
// escape any character with a special meaning in CSS using CSS.escape()
|
|
results.push($tw.utils.escapeCSS(title));
|
|
});
|
|
return results;
|
|
};
|
|
|
|
})();
|