Merge pull request #2042 from thelounge/xpaw/fix-2040

Fix crash when hostname is changed in lockNetwork mode
This commit is contained in:
Pavel Djundik 2018-02-07 23:03:55 +02:00 committed by GitHub
commit 14847260b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 3 deletions

View file

@ -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.",

View file

@ -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;

View file

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