From 259f37320745791ac467bb18ba15849409faf802 Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 12 Mar 2018 21:41:25 +0300 Subject: [PATCH] properly cut URL#href on '?' when sending a POST request fixes #365 --- js/messaging.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/js/messaging.js b/js/messaging.js index 7c289f5f..e5bb1f86 100644 --- a/js/messaging.js +++ b/js/messaging.js @@ -449,10 +449,20 @@ function sessionStorageHash(name) { }; } - +/** + * @param {String} url + * @param {Object} params + * @param {String} [params.method] + * @param {String|Object} [params.body] + * @param {String} [params.responseType] arraybuffer, blob, document, json, text + * @param {Number} [params.requiredStatusCode] resolved when matches, otherwise rejected + * @param {Number} [params.timeout] ms + * @param {Object} [params.headers] {name: value} + * @returns {Promise} + */ function download(url, { - method = url.includes('?') ? 'POST' : 'GET', - body = url.includes('?') ? url.slice(url.indexOf('?')) : null, + method = 'GET', + body = null, responseType = 'text', requiredStatusCode = 200, timeout = 10e3, @@ -460,6 +470,12 @@ function download(url, { 'Content-type': 'application/x-www-form-urlencoded', }, } = {}) { + const queryPos = url.indexOf('?'); + if (queryPos > 0) { + method = 'POST'; + body = url.slice(queryPos); + url = url.slice(0, queryPos); + } return new Promise((resolve, reject) => { url = new URL(url); if (url.protocol === 'file:' && FIREFOX) {