From 51215c1cbec4e66ce9865ee8897bbd58b7efe057 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Wed, 14 Aug 2013 18:53:13 +0000 Subject: [PATCH] add and use Ox.decodeURI and Ox.decodeURIComponent --- source/Ox.UI/js/Core/Cookies.js | 2 +- source/Ox.UI/js/Core/URL.js | 2 +- source/Ox/js/String.js | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/source/Ox.UI/js/Core/Cookies.js b/source/Ox.UI/js/Core/Cookies.js index a29e374b..4da89ae7 100644 --- a/source/Ox.UI/js/Core/Cookies.js +++ b/source/Ox.UI/js/Core/Cookies.js @@ -12,7 +12,7 @@ Ox.Cookies = function() { if (document.cookie && document.cookie != '') { document.cookie.split('; ').forEach(function(cookie) { name = cookie.split('=')[0]; - value[name] = decodeURIComponent(cookie.substring(name.length + 1)); + value[name] = Ox.decodeURIComponent(cookie.substring(name.length + 1)); }); } return value; diff --git a/source/Ox.UI/js/Core/URL.js b/source/Ox.UI/js/Core/URL.js index b7a58546..a03dfa6a 100644 --- a/source/Ox.UI/js/Core/URL.js +++ b/source/Ox.UI/js/Core/URL.js @@ -563,7 +563,7 @@ Ox.URL = function(options) { } function decodeValue(value) { - return decodeURIComponent(value); + return Ox.decodeURIComponent(value); } function encodeValue(value) { diff --git a/source/Ox/js/String.js b/source/Ox/js/String.js index 8f28a701..128556a6 100644 --- a/source/Ox/js/String.js +++ b/source/Ox/js/String.js @@ -24,6 +24,24 @@ Ox.clean = function(string) { })).join('\n'); }; +/*@ +Ox.decodeURIComponent Decodes URI + Unlike window.decodeURI, this doesn't throw on trailing '%'. + (string) -> Decoded string +@*/ +Ox.decodeURI = function(string) { + return decodeURIComponent(string.replace(/%(?![0-7][0-9A-F])/g, '%25')); +}; + +/*@ +Ox.decodeURIComponent Decodes URI component + Unlike window.decodeURIComponent, this doesn't throw on trailing '%'. + (string) -> Decoded string +@*/ +Ox.decodeURIComponent = function(string) { + return decodeURIComponent(string.replace(/%(?![0-7][0-9A-F])/g, '%25')); +}; + /*@ Ox.endsWith Tests if a string ends with a given substring Equivalent to `new RegExp(Ox.escapeRegExp(substring) + '$').test(string)`.