Skip to content

Fix/issue #579 #580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2020
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
2 changes: 1 addition & 1 deletion src/CommandLine/UnParserExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private static string FormatValue(Specification spec, object value)

private static object FormatWithQuotesIfString(object value)
{
if (value is DateTime || value is TimeSpan || value is DateTimeOffset) return $"\"{value}\"";
if (value is DateTime || value is DateTimeOffset) return $"\"{value}\"";
Func<string, string> doubQt = v
=> v.Contains("\"") ? v.Replace("\"", "\\\"") : v;

Expand Down
16 changes: 16 additions & 0 deletions tests/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,22 @@ public void Parse_TimeSpan()
expectedResult.Should().BeEquivalentTo(((Parsed<Options_With_TimeSpan>)result).Value);
}

#region Issue 579
[Fact]
public void Should_not_parse_quoted_TimeSpan()
{
// Exercize system
var result = InvokeBuild<Options_With_TimeSpan>(new[] { "--duration=\"00:42:00\"" });

var outcome = result as NotParsed<Options_With_TimeSpan>;

// Verify outcome
outcome.Should().NotBeNull();
outcome.Errors.Should().NotBeNullOrEmpty()
.And.HaveCount(1)
.And.OnlyContain(e => e.GetType().Equals(typeof(BadFormatConversionError)));
}
#endregion

[Fact]
public void OptionClass_IsImmutable_HasNoCtor()
Expand Down
13 changes: 12 additions & 1 deletion tests/CommandLine.Tests/Unit/UnParserExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ public static void UnParsing_instance_with_dash_in_value_and_dashdash_disabled_r
.Should().BeEquivalentTo("-something with dash");
}

#region Issue 579
[Fact]
public static void UnParsing_instance_with_TimeSpan_returns_the_value_unquoted_in_command_line()
{
var options = new Options_With_TimeSpan { Duration = TimeSpan.FromMinutes(1) };
new Parser()
.FormatCommandLine(options)
.Should().Be("--duration 00:01:00");
}
#endregion

#region PR 550

[Fact]
Expand Down Expand Up @@ -174,7 +185,7 @@ public static void UnParsing_instance_with_timespan()
var options = new Options_TimeSpan { Start = ts };
var result = new Parser()
.FormatCommandLine(options)
.Should().BeEquivalentTo("--start \"01:02:03\"");
.Should().BeEquivalentTo("--start 01:02:03"); //changed for issue 579
}

[Theory]
Expand Down