From 9961bffd4878ce8b074f7e0689c2bfdb2cf9ce06 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 29 Jan 2020 17:40:16 +0100 Subject: [PATCH] Fix XXX in sframe-common-outer --- www/common/common-hash.js | 10 ++++++---- www/common/sframe-common-outer.js | 31 +++++++++++++------------------ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/www/common/common-hash.js b/www/common/common-hash.js index 22b11b4af..ad32e65c8 100644 --- a/www/common/common-hash.js +++ b/www/common/common-hash.js @@ -193,7 +193,8 @@ Version 1 return { embed: parsed.embed, present: parsed.present, - ownerKey: parsed.ownerKey + ownerKey: parsed.ownerKey, + password: parsed.password }; }; if (hash.slice(0,1) !== '/' && hash.length >= 56) { // Version 0 @@ -209,7 +210,7 @@ Version 1 var hash = hashArr.slice(0, 5).join('/') + '/'; var owner = typeof(opts.ownerKey) !== "undefined" ? opts.ownerKey : parsed.ownerKey; if (owner) { hash += owner + '/'; } - if (parsed.password) { hash += 'p/'; } + if (parsed.password || opts.password) { hash += 'p/'; } if (opts.embed) { hash += 'embed/'; } if (opts.present) { hash += 'present/'; } return hash; @@ -258,7 +259,8 @@ Version 1 return { embed: parsed.embed, present: parsed.present, - ownerKey: parsed.ownerKey + ownerKey: parsed.ownerKey, + password: parsed.password }; }; @@ -266,7 +268,7 @@ Version 1 var hash = hashArr.slice(0, 4).join('/') + '/'; var owner = typeof(opts.ownerKey) !== "undefined" ? opts.ownerKey : parsed.ownerKey; if (owner) { hash += owner + '/'; } - if (parsed.password) { hash += 'p/'; } + if (parsed.password || opts.password) { hash += 'p/'; } if (opts.embed) { hash += 'embed/'; } if (opts.present) { hash += 'present/'; } return hash; diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index a34faa0fc..1d4233ccc 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -188,15 +188,24 @@ define([ secret = Utils.secret = Utils.Hash.getSecrets(parsed.type, parsed.hash, password); Cryptpad.getShareHashes(secret, waitFor(function (err, h) { hashes = h; - /* XXX this won't happen again: we don't need to update the rendered hash + // Update the rendered hash and the full hash with the "password" settings if (password && !parsed.hashData.password) { + var opts = parsed.getOptions(); + opts.password = true; + + // Full hash + currentPad.href = parsed.getUrl(opts); + if (parsed.hashData) { + currentPad.hash = parsed.hashData.getHash(opts); + } + // Rendered (maybe hidden) hash + var renderedParsed = Utils.Hash.parsePadUrl(window.location.href); var ohc = window.onhashchange; window.onhashchange = function () {}; - window.location.hash = h.fileHash || h.editHash || h.viewHash || window.location.hash; + window.location.href = renderedParsed.getUrl(opts); window.onhashchange = ohc; ohc({reset: true}); } - */ })); }; @@ -276,13 +285,6 @@ define([ var noPadData = function (err) { sframeChan.event("EV_PAD_NODATA", err); }; - // Hidden hash: can't find requestd edit URL in our drives: ask - var badPadData = function (cb) { - // If we requested edit but we only know view: ??? - setTimeout(function () { - cb(true); - }); // XXX ask in inner? - }; var newHref; nThen(function (w) { @@ -305,13 +307,7 @@ define([ } // Data found but weaker? warn if (edit && !res.href) { - return void badPadData(w(function (load) { - if (!load) { - w.abort(); - return; - } - newHref = res.roHref; - })); + newHref = res.roHref; } // We have good data, keep the hash in memory newHref = edit ? res.href : (res.roHref || res.href); @@ -1337,7 +1333,6 @@ define([ rtStarted = true; var replaceHash = function (hash) { - // XXX Always put the full hash here. // The pad has just been created but is not stored yet. We'll switch // to hidden hash once the pad is stored if (window.history && window.history.replaceState) {