1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-05 00:42:10 +03:00

Make the display_name check for contains rather than equality. Add UT.

This commit is contained in:
Kegan Dougal
2015-11-09 16:50:10 +00:00
parent b0655d0431
commit b231f19ec6
2 changed files with 12 additions and 3 deletions

View File

@@ -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 <code>displayName</code> contains the <code>address</code>.
*/
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."
);
}

View File

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