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();
+ });
+
});
});