From 7fe3e2f90aea87f3db2d52efc80f445a8591cfd5 Mon Sep 17 00:00:00 2001
From: Michael Telatynski <7t3chguy@gmail.com>
Date: Mon, 18 Jun 2018 12:27:25 +0100
Subject: [PATCH] invert argument to make it positive without breaking
backwards compat
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
---
src/base-apis.js | 4 ++--
src/http-api.js | 11 +++++++----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/base-apis.js b/src/base-apis.js
index 8c53969ea..bf2381790 100644
--- a/src/base-apis.js
+++ b/src/base-apis.js
@@ -1071,9 +1071,9 @@ MatrixBaseApis.prototype.searchUserDirectory = function(opts) {
* @param {string=} opts.name Name to give the file on the server. Defaults
* to file.name.
*
- * @param {boolean=} opts.omitFilename if true will not send the filename,
+ * @param {boolean=} opts.includeFilename if false will not send the filename,
* e.g for encrypted file uploads where filename leaks are undesirable.
- * Defaults to false.
+ * Defaults to true.
*
* @param {string=} opts.type Content-type for the upload. Defaults to
* file.type, or applicaton/octet-stream.
diff --git a/src/http-api.js b/src/http-api.js
index 7326892c4..b753d6bf8 100644
--- a/src/http-api.js
+++ b/src/http-api.js
@@ -118,9 +118,9 @@ module.exports.MatrixHttpApi.prototype = {
* @param {string=} opts.name Name to give the file on the server. Defaults
* to file.name.
*
- * @param {boolean=} opts.omitFilename if true will not send the filename,
+ * @param {boolean=} opts.includeFilename if false will not send the filename,
* e.g for encrypted file uploads where filename leaks are undesirable.
- * Defaults to false.
+ * Defaults to true.
*
* @param {string=} opts.type Content-type for the upload. Defaults to
* file.type, or applicaton/octet-stream.
@@ -156,6 +156,9 @@ module.exports.MatrixHttpApi.prototype = {
opts = {};
}
+ // default opts.includeFilename to true (ignoring falsey values)
+ const includeFilename = opts.includeFilename !== false;
+
// if the file doesn't have a mime type, use a default since
// the HS errors if we don't supply one.
const contentType = opts.type || file.type || 'application/octet-stream';
@@ -279,7 +282,7 @@ module.exports.MatrixHttpApi.prototype = {
const queryArgs = [];
- if (!opts.omitFilename && fileName) {
+ if (includeFilename && fileName) {
queryArgs.push("filename=" + encodeURIComponent(fileName));
}
@@ -305,7 +308,7 @@ module.exports.MatrixHttpApi.prototype = {
} else {
const queryParams = {};
- if (!opts.omitFilename && fileName) {
+ if (includeFilename && fileName) {
queryParams.filename = fileName;
}