Browse Source

Fix logic for quoted arguments

pull/1123/head
Joe4evr 7 years ago
parent
commit
06d66a5942
3 changed files with 40 additions and 7 deletions
  1. +10
    -3
      src/Discord.Net.Commands/Readers/NamedArgumentTypeReader.cs
  2. +4
    -4
      test/Discord.Net.Tests/Discord.Net.Tests.csproj
  3. +26
    -0
      test/Discord.Net.Tests/Tests.TypeReaders.cs

+ 10
- 3
src/Discord.Net.Commands/Readers/NamedArgumentTypeReader.cs View File

@@ -96,13 +96,20 @@ namespace Discord.Commands


PropertyInfo GetPropAndValue(out string argv) PropertyInfo GetPropAndValue(out string argv)
{ {
bool quoted = state == ReadState.InQuotedArgument;
state = (currentRead == input.Length) state = (currentRead == input.Length)
? ReadState.End ? ReadState.End
: ReadState.LookingForParameter; : ReadState.LookingForParameter;


var prop = _tProps[currentParam];
argv = input.Substring(beginRead, currentRead - beginRead);
return prop;
if (quoted)
{
argv = input.Substring(beginRead + 1, currentRead - beginRead - 1);
currentRead++;
}
else
argv = input.Substring(beginRead, currentRead - beginRead);

return _tProps[currentParam];
} }
} }




+ 4
- 4
test/Discord.Net.Tests/Discord.Net.Tests.csproj View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<RootNamespace>Discord</RootNamespace> <RootNamespace>Discord</RootNamespace>
@@ -24,8 +24,8 @@
<PackageReference Include="Akavache" Version="5.0.0" /> <PackageReference Include="Akavache" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" /> <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="xunit.runner.reporters" Version="2.3.1" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="xunit.runner.reporters" Version="2.4.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

+ 26
- 0
test/Discord.Net.Tests/Tests.TypeReaders.cs View File

@@ -32,6 +32,32 @@ namespace Discord
Assert.Equal(expected: 42, actual: m.Foo); Assert.Equal(expected: 42, actual: m.Foo);
Assert.Equal(expected: "hello", actual: m.Bar); Assert.Equal(expected: "hello", actual: m.Bar);
} }

[Fact]
public async Task TestQuotedArgumentValue()
{
var commands = new CommandService();
var module = await commands.AddModuleAsync<TestModule>(null);

Assert.NotNull(module);
Assert.NotEmpty(module.Commands);

var cmd = module.Commands[0];
Assert.NotNull(cmd);
Assert.NotEmpty(cmd.Parameters);

var param = cmd.Parameters[0];
Assert.NotNull(param);
Assert.True(param.IsRemainder);

var result = await param.ParseAsync(null, "bar: 《hello》 foo: 42");
Assert.True(result.IsSuccess);

var m = result.BestMatch as ArgumentType;
Assert.NotNull(m);
Assert.Equal(expected: 42, actual: m.Foo);
Assert.Equal(expected: "hello", actual: m.Bar);
}
} }


[NamedArgumentType] [NamedArgumentType]


Loading…
Cancel
Save