writing tests for pageKey function, fixing always added padding bug

This commit is contained in:
El RIDO
2017-02-05 18:03:42 +01:00
parent a97b94640e
commit 67f71f4dd6
2 changed files with 47 additions and 19 deletions

View File

@@ -290,31 +290,16 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
*/
pageKey: function()
{
var key = window.location.hash.substring(1),
i = key.indexOf('&');
// Some web 2.0 services and redirectors add data AFTER the anchor
// (such as &utm_source=...). We will strip any additional data.
var key = window.location.hash.substring(1), // Get key
i = key.indexOf('=');
// First, strip everything after the equal sign (=) which signals end of base64 string.
if (i > -1)
{
key = key.substring(0, i + 1);
}
// If the equal sign was not present, some parameters may remain:
i = key.indexOf('&');
if (i > -1)
{
key = key.substring(0, i);
}
// Then add trailing equal sign if it's missing
if (key.charAt(key.length - 1) !== '=')
{
key += '=';
}
return key;
},