From aee1ec27396da01f247b18c224f7a7cacc54323d Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 7 Feb 2018 11:56:49 +0200 Subject: [PATCH] Fix crash when hostname is changed in lockNetwork mode Fixes #2040 --- src/client.js | 2 +- src/models/chan.js | 8 ++++++-- test/models/chan.js | 11 +++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/client.js b/src/client.js index 3c51741f..e8adfb3f 100644 --- a/src/client.js +++ b/src/client.js @@ -224,7 +224,7 @@ Client.prototype.connect = function(args) { if (config.lockNetwork) { // This check is needed to prevent invalid user configurations - if (args.host && args.host.length > 0 && args.host !== config.defaults.host) { + if (!Helper.config.public && args.host && args.host.length > 0 && args.host !== config.defaults.host) { network.channels[0].pushMessage(client, new Msg({ type: Msg.Type.ERROR, text: "Hostname you specified is not allowed.", diff --git a/src/models/chan.js b/src/models/chan.js index c0c5d0df..eef30992 100644 --- a/src/models/chan.js +++ b/src/models/chan.js @@ -98,6 +98,12 @@ Chan.prototype.dereferencePreviews = function(messages) { }; Chan.prototype.getSortedUsers = function(irc) { + const users = Array.from(this.users.values()); + + if (!irc || !irc.network || !irc.network.options || !irc.network.options.PREFIX) { + return users; + } + var userModeSortPriority = {}; irc.network.options.PREFIX.forEach((prefix, index) => { userModeSortPriority[prefix.symbol] = index; @@ -105,8 +111,6 @@ Chan.prototype.getSortedUsers = function(irc) { userModeSortPriority[""] = 99; // No mode is lowest - const users = Array.from(this.users.values()); - return users.sort(function(a, b) { if (a.mode === b.mode) { return a.nick.toLowerCase() < b.nick.toLowerCase() ? -1 : 1; diff --git a/test/models/chan.js b/test/models/chan.js index d9c2c182..fbd00852 100644 --- a/test/models/chan.js +++ b/test/models/chan.js @@ -86,6 +86,17 @@ describe("Chan", function() { return chan.getSortedUsers(network).map((u) => u.nick); }; + it("returns unsorted list on null irc object", function() { + const chan = new Chan(); + [ + "JocelynD", "YaManicKill", "astorije", "xPaw", "Max-P", + ].forEach((nick) => chan.setUser(new User({nick: nick}))); + + expect(chan.getSortedUsers().map((u) => u.nick)).to.deep.equal([ + "JocelynD", "YaManicKill", "astorije", "xPaw", "Max-P", + ]); + }); + it("should sort a simple user list", function() { const chan = new Chan(); [