From a51a35da70e4c879cd53c83a7ab57111d8de8064 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 28 Apr 2017 15:47:31 +0200 Subject: [PATCH] Fix an issue with hashes ending with a slash --- www/common/common-hash.js | 5 +++++ www/common/cryptpad-common.js | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/www/common/common-hash.js b/www/common/common-hash.js index b282a1b94..1d731cec0 100644 --- a/www/common/common-hash.js +++ b/www/common/common-hash.js @@ -270,5 +270,10 @@ Version 2 return '/blob/' + id.slice(0,2) + '/' + id; }; + var serializeHash = Hash.serializeHash = function (hash) { + if (hash && hash.slice(-1) !== "/") { hash += "/"; } + return hash; + }; + return Hash; }); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 20f68f3be..a2d2f5aaf 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -82,6 +82,7 @@ define([ common.createChannelId = Hash.createChannelId; common.findWeaker = Hash.findWeaker; common.findStronger = Hash.findStronger; + common.serializeHash = Hash.serializeHash; // History common.getHistory = function (config) { return History.create(common, config); }; @@ -166,6 +167,7 @@ define([ var login = common.login = function (hash, name, cb) { if (!hash) { throw new Error('expected a user hash'); } if (!name) { throw new Error('expected a user name'); } + hash = common.serializeHash(hash); localStorage.setItem(userHashKey, hash); localStorage.setItem(userNameKey, name); if (cb) { cb(); } @@ -216,11 +218,12 @@ define([ }; var getUserHash = common.getUserHash = function () { - var hash; - [sessionStorage, localStorage].some(function (s) { - var h = s[userHashKey]; - if (h) { return (hash = h); } - }); + var hash = localStorage[userHashKey]; + + if (hash) { + var sHash = common.serializeHash(hash); + if (sHash !== hash) { localStorage[userHashKey] = sHash; } + } return hash; };