From b231f19ec6e161db24aaa83d3da5eab97b841e3d Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 9 Nov 2015 16:50:10 +0000 Subject: [PATCH] Make the display_name check for contains rather than equality. Add UT. --- lib/client.js | 6 +++--- spec/unit/matrix-client.spec.js | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/client.js b/lib/client.js index 06e101285..901a9bf92 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1363,15 +1363,15 @@ MatrixClient.prototype.inviteByEmail = function(roomId, email, displayName, call * @param {module:client.callback} callback Optional. * @return {module:client.Promise} Resolves: TODO * @return {module:http-api.MatrixError} Rejects: with an error response. - * @throws If displayName === address. + * @throws If displayName contains the address. */ MatrixClient.prototype.inviteByThreePid = function(roomId, medium, address, displayName, idServer, callback) { if (utils.isFunction(idServer)) { callback = idServer; idServer = undefined; } idServer = idServer || this.getIdentityServerUrl(); - if (displayName === address) { + if (displayName && displayName.indexOf(address) >= 0) { throw new Error( - "The display name is the same as the address. This leaks the 3PID " + + "The display name contains the address. This leaks the 3PID " + "address to everyone in the room." ); } diff --git a/spec/unit/matrix-client.spec.js b/spec/unit/matrix-client.spec.js index d59bdd565..99bade688 100644 --- a/spec/unit/matrix-client.spec.js +++ b/spec/unit/matrix-client.spec.js @@ -372,5 +372,14 @@ describe("MatrixClient", function() { expect(httpLookups.length).toEqual(0); }); + it("should throw if the displayName contains the address in it", + function() { + expect(function() { + client.inviteByEmail( + roomId, "alice@gmail.com", "My Friend Alice (alice@gmail.com)" + ); + }).toThrow(); + }); + }); });