1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-30 05:52:27 +01:00

Countermeasure for "Error: malformed URI sequence".

This error occurs in encodeURI when URL is encoded by not UTF-8 encoding.
This commit is contained in:
anekos
2009-11-25 14:49:17 +09:00
parent a8f985081c
commit 24b38ffdd4

13
common/content/statusline.js Normal file → Executable file
View File

@@ -61,9 +61,20 @@ const StatusLine = Module("statusline", {
updateUrl: function updateUrl(url) {
// ripped from Firefox; modified
function losslessDecodeURI(url) {
// Countermeasure for "Error: malformed URI sequence".
// This error occurs when URL is encoded by not UTF-8 encoding.
function _decodeURI(url) {
try {
return decodeURI(url);
}
catch (e) {
return url;
}
};
// 1. decodeURI decodes %25 to %, which creates unintended
// encoding sequences.
url = url.split("%25").map(decodeURI).join("%25");
url = url.split("%25").map(_decodeURI).join("%25");
// 2. Re-encode whitespace so that it doesn't get eaten away
// by the location bar (bug 410726).
url = url.replace(/[\r\n\t]/g, encodeURIComponent);