From 5b21911341744a5cdef9743f754f049adaef03af Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 16 Mar 2018 12:26:39 +0100 Subject: [PATCH 1/3] pass flow tests --- rpc.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rpc.js b/rpc.js index 3ad1a9a42..9cdb440f3 100644 --- a/rpc.js +++ b/rpc.js @@ -992,6 +992,9 @@ var owned_upload_complete = function (Env, safeKey, cb) { } var oldPath = makeFilePath(Env.paths.staging, safeKey); + if (typeof(oldPath) !== 'string') { + return void cb('EINVAL_CONFIG'); + } // construct relevant paths var root = Env.paths.staging; @@ -1054,6 +1057,9 @@ var owned_upload_complete = function (Env, safeKey, cb) { })); }).nThen(function (w) { // move the existing file to its new path + + // flow is dumb and I need to guard against this which will never happen + /*:: if (typeof(oldPath) === 'object') { throw new Error('should never happen'); } */ Fs.rename(oldPath /* XXX */, finalPath, w(function (e) { if (e) { w.abort(); @@ -1217,7 +1223,6 @@ RPC.create = function ( var pinPath = paths.pin = keyOrDefaultString('pinPath', './pins'); var blobPath = paths.blob = keyOrDefaultString('blobPath', './blob'); var blobStagingPath = paths.staging = keyOrDefaultString('blobStagingPath', './blobstage'); - console.log(blobStagingPath); var isUnauthenticateMessage = function (msg) { return msg && msg.length === 2 && isUnauthenticatedCall(msg[0]); From 96a63a3b7bf6c61d5c2110d2db73c8cb76fa80b8 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 19 Mar 2018 16:56:09 +0100 Subject: [PATCH 2/3] fix weird checkbox logic in share menu --- www/common/common-ui-elements.js | 18 +++++++++--------- www/common/common-util.js | 7 +++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 07ad3d98d..02a929ad1 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -241,7 +241,6 @@ define([ type: 'radio', name: 'cp-share-editable', value: 1, - checked: 'checked' }), h('label', { 'for': 'cp-share-editable-true' }, Messages.share_linkEdit), h('input#cp-share-editable-false.cp-share-editable-value', { @@ -271,12 +270,12 @@ define([ ]); if (!hashes.editHash) { $(link).find('#cp-share-editable-false').attr('checked', true); - $(link).find('#cp-share-editable-true').attr('disabled', true); + $(link).find('#cp-share-editable-true').removeAttr('checked').attr('disabled', true); } var saveValue = function () { - var edit = $(link).find('#cp-share-editable-true').is(':checked'); - var embed = $(link).find('#cp-share-embed').is(':checked'); - var present = $(link).find('#cp-share-present').is(':checked'); + var edit = Util.isChecked($(link).find('#cp-share-editable-true')); + var embed = Util.isChecked($(link).find('#cp-share-embed')); + var present = Util.isChecked($(link).find('#cp-share-present')); common.setAttribute(['general', 'share'], { edit: edit, embed: embed, @@ -285,9 +284,9 @@ define([ }; var getLinkValue = function (initValue) { var val = initValue || {}; - var edit = initValue ? val.edit : $(link).find('#cp-share-editable-true').is(':checked'); - var embed = initValue ? val.embed : $(link).find('#cp-share-embed').is(':checked'); - var present = initValue ? val.present : $(link).find('#cp-share-present').is(':checked'); + var edit = initValue ? val.edit : Util.isChecked($(link).find('#cp-share-editable-true')); + var embed = initValue ? val.embed : Util.isChecked($(link).find('#cp-share-embed')); + var present = initValue ? val.present : Util.isChecked($(link).find('#cp-share-present')); var hash = (edit && hashes.editHash) ? hashes.editHash : hashes.viewHash; var href = origin + pathname + '#' + hash; @@ -374,6 +373,7 @@ define([ if (val.edit === false) { $(link).find('#cp-share-editable-false').attr('checked', true); } + else { $(link).find('#cp-share-editable-true').attr('checked', true); } if (val.embed) { $(link).find('#cp-share-embed').attr('checked', true); } if (val.present) { $(link).find('#cp-share-present').attr('checked', true); } $(link).find('#cp-share-link-preview').val(getLinkValue(val)); @@ -1681,7 +1681,7 @@ define([ $element.attr('data-type', p); $element.click(function () { $modal.hide(); - if ($advanced && $advanced.is(':checked')) { + if ($advanced && Util.isChecked($advanced)) { common.sessionStorage.put(Constants.displayPadCreationScreen, true, function (){ common.openURL('/' + p + '/'); }); diff --git a/www/common/common-util.js b/www/common/common-util.js index 98eda7373..c16a2cdfd 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -246,6 +246,13 @@ define([], function () { } }; + Util.isChecked = function (el) { + // could be nothing... + if (!el) { return false; } + // jquery or dom elements should both be fine with this + return Boolean($(el).prop('checked')); + }; + return Util; }); }(self)); From bd6b6dcb49fb399d49b531897b5009c9c29e5e52 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 19 Mar 2018 17:13:44 +0100 Subject: [PATCH 3/3] actually fix weird checkbox logic, and lint compliance --- www/common/common-ui-elements.js | 8 ++++---- www/common/common-util.js | 12 ++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index bffc6e2d5..50e532204 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -371,11 +371,11 @@ define([ common.getAttribute(['general', 'share'], function (err, val) { val = val || {}; if (val.edit === false) { - $(link).find('#cp-share-editable-false').attr('checked', true); + $(link).find('#cp-share-editable-false').prop('checked', true); } - else { $(link).find('#cp-share-editable-true').attr('checked', true); } - if (val.embed) { $(link).find('#cp-share-embed').attr('checked', true); } - if (val.present) { $(link).find('#cp-share-present').attr('checked', true); } + else { $(link).find('#cp-share-editable-true').prop('checked', true); } + if (val.embed) { $(link).find('#cp-share-embed').prop('checked', true); } + if (val.present) { $(link).find('#cp-share-present').prop('checked', true); } $(link).find('#cp-share-link-preview').val(getLinkValue(val)); }); common.getMetadataMgr().onChange(function () { diff --git a/www/common/common-util.js b/www/common/common-util.js index c16a2cdfd..a67ba6673 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -249,8 +249,16 @@ define([], function () { Util.isChecked = function (el) { // could be nothing... if (!el) { return false; } - // jquery or dom elements should both be fine with this - return Boolean($(el).prop('checked')); + // check if it's a dom element + if (typeof(el.tagName) !== 'undefined') { + return Boolean(el.checked); + } + // sketchy test to see if it's jquery + if (typeof(el.prop) === 'function') { + return Boolean(el.prop('checked')); + } + // else just say it's not checked + return false; }; return Util;