Browse Source

Ensure that the collection passed into command service is not null

pull/943/head
Chris Johnston 7 years ago
parent
commit
820f9e3648
2 changed files with 7 additions and 6 deletions
  1. +5
    -4
      src/Discord.Net.Commands/CommandParser.cs
  2. +2
    -2
      src/Discord.Net.Commands/CommandService.cs

+ 5
- 4
src/Discord.Net.Commands/CommandParser.cs View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text;
@@ -29,8 +29,8 @@ namespace Discord.Commands
// local helper functions
bool IsOpenQuote(IReadOnlyDictionary<char, char> dict, char ch)
{
// return if the key is contained in the dictionary if it exists
if (dict != null)
// return if the key is contained in the dictionary if it is populated
if (dict.Count != 0)
return dict.ContainsKey(ch);
// or otherwise if it is the default double quote
return c == '\"';
@@ -39,7 +39,8 @@ namespace Discord.Commands
char GetMatch(IReadOnlyDictionary<char, char> dict, char ch)
{
// get the corresponding value for the key, if it exists
if (dict != null && dict.TryGetValue(c, out var value))
// and if the dictionary is populated
if (dict.Count != 0 && dict.TryGetValue(c, out var value))
return value;
// or get the default pair of the default double quote
return '\"';


+ 2
- 2
src/Discord.Net.Commands/CommandService.cs View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
@@ -46,7 +46,7 @@ namespace Discord.Commands
_ignoreExtraArgs = config.IgnoreExtraArgs;
_separatorChar = config.SeparatorChar;
_defaultRunMode = config.DefaultRunMode;
_quotationMarkAliasMap = config.QuotationMarkAliasMap?.ToImmutableDictionary();
_quotationMarkAliasMap = (config.QuotationMarkAliasMap ?? new Dictionary<char, char>()).ToImmutableDictionary();
if (_defaultRunMode == RunMode.Default)
throw new InvalidOperationException("The default run mode cannot be set to Default.");



Loading…
Cancel
Save