Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,6 @@ public Task Should_Return_Correct_Text()
}
}

public sealed class InvalidCharacterInOptionName
{
public sealed class Settings : CommandSettings
{
[CommandOption("--f$oo")]
public string Foo { get; set; } = null!;
}

[Fact]
[Expectation("InvalidCharacterInOptionName")]
public Task Should_Return_Correct_Text()
{
// Given, When
var result = Fixture.Run<Settings>();

// Then
result.Exception.Message.ShouldBe("Encountered invalid character '$' in option name.");
return Verifier.Verify(result.Output);
}
}

public sealed class LongOptionMustHaveMoreThanOneCharacter
{
public sealed class Settings : CommandSettings
Expand Down Expand Up @@ -171,27 +150,6 @@ public Task Should_Return_Correct_Text()
}
}

public sealed class InvalidCharacterInValueName
{
public sealed class Settings : CommandSettings
{
[CommandOption("-f|--foo <F$OO>")]
public string Foo { get; set; } = null!;
}

[Fact]
[Expectation("InvalidCharacterInValueName")]
public Task Should_Return_Correct_Text()
{
// Given, When
var result = Fixture.Run<Settings>();

// Then
result.Exception.Message.ShouldBe("Encountered invalid character '$' in value name.");
return Verifier.Verify(result.Output);
}
}

public sealed class MissingLongAndShortName
{
public sealed class Settings : CommandSettings
Expand Down
17 changes: 0 additions & 17 deletions src/Spectre.Console.Cli.Tests/CommandOptionAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,6 @@ public void Should_Throw_If_Option_Have_No_Name(string template)
e.Message.ShouldBe("Options without name are not allowed."));
}

[Theory]
[InlineData("--foo|-foo[b", '[')]
[InlineData("--foo|-f€b", '€')]
[InlineData("--foo|-foo@b", '@')]
public void Should_Throw_If_Option_Contains_Invalid_Name(string template, char invalid)
{
// Given, When
var result = Record.Exception(() => new CommandOptionAttribute(template));

// Then
result.ShouldBeOfType<CommandTemplateException>().And(e =>
{
e.Message.ShouldBe($"Encountered invalid character '{invalid}' in option name.");
e.Template.ShouldBe(template);
});
}

[Theory]
[InlineData("--foo <HELLO-WORLD>", "HELLO-WORLD")]
[InlineData("--foo <HELLO_WORLD>", "HELLO_WORLD")]
Expand Down

This file was deleted.

This file was deleted.

29 changes: 0 additions & 29 deletions src/Spectre.Console.Cli/CommandTemplateException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,6 @@ internal static CommandTemplateException OptionNamesCannotStartWithDigit(string
"Invalid option name.");
}

internal static CommandTemplateException InvalidCharacterInOptionName(string template, TemplateToken token, char character)
{
// Rewrite the token to point to the invalid character instead of the whole value.
var position = (token.TokenKind == TemplateToken.Kind.ShortName
? token.Position + 1
: token.Position + 2) + token.Value.OrdinalIndexOf(character);

token = new TemplateToken(
token.TokenKind, position,
token.Value, character.ToString(CultureInfo.InvariantCulture));

return CommandLineTemplateExceptionFactory.Create(template, token,
$"Encountered invalid character '{character}' in option name.",
"Invalid character.");
}

internal static CommandTemplateException LongOptionMustHaveMoreThanOneCharacter(string template, TemplateToken token)
{
// Rewrite the token to point to the option name instead of the whole option.
Expand Down Expand Up @@ -127,19 +111,6 @@ internal static CommandTemplateException MultipleOptionValuesAreNotSupported(str
"Too many option values.");
}

internal static CommandTemplateException InvalidCharacterInValueName(string template, TemplateToken token, char character)
{
// Rewrite the token to point to the invalid character instead of the whole value.
token = new TemplateToken(
token.TokenKind,
token.Position + 1 + token.Value.OrdinalIndexOf(character),
token.Value, character.ToString(CultureInfo.InvariantCulture));

return CommandLineTemplateExceptionFactory.Create(template, token,
$"Encountered invalid character '{character}' in value name.",
"Invalid character.");
}

internal static CommandTemplateException MissingLongAndShortName(string template, TemplateToken? token)
{
return CommandLineTemplateExceptionFactory.Create(template, token,
Expand Down
17 changes: 0 additions & 17 deletions src/Spectre.Console.Cli/Internal/Configuration/TemplateParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ public static OptionResult ParseOptionTemplate(string template)
{
throw CommandTemplateException.OptionNamesCannotStartWithDigit(template, token);
}

foreach (var character in token.Value)
{
if (!char.IsLetterOrDigit(character) && character != '-' && character != '_' && character != '?')
{
throw CommandTemplateException.InvalidCharacterInOptionName(template, token, character);
}
}
}

if (token.TokenKind == TemplateToken.Kind.LongName)
Expand Down Expand Up @@ -115,15 +107,6 @@ public static OptionResult ParseOptionTemplate(string template)
throw CommandTemplateException.MultipleOptionValuesAreNotSupported(template, token);
}

foreach (var character in token.Value)
{
if (!char.IsLetterOrDigit(character) &&
character != '=' && character != '-' && character != '_' && character != '|')
{
throw CommandTemplateException.InvalidCharacterInValueName(template, token, character);
}
}

result.Value = token.Value.ToUpperInvariant();
result.ValueIsOptional = token.TokenKind == TemplateToken.Kind.OptionalValue;
}
Expand Down