Skip to content
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

Fixed bug #1495 Not properly handling one argument with spaces #1501

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions source/Nuke.Common.Tests/SettingsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ public void TestDocker()
{
Assert(new DockerAttachSettings()
.SetDetachKeys("detach-keys")
.SetContainer("container")
.SetLogLevel(DockerLogLevel.debug),
"attach --detach-keys detach-keys container --log-level debug");
.SetLogLevel(DockerLogLevel.debug)
.SetContainer("container"),
"attach --detach-keys detach-keys --log-level debug container");
}

[Fact]
Expand Down
14 changes: 11 additions & 3 deletions source/Nuke.Tooling.Tests/ArgumentStringHandlerTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Maintainers of NUKE.
// Copyright 2023 Maintainers of NUKE.
// Distributed under the MIT License.
// https://github.com/nuke-build/nuke/blob/master/LICENSE

Expand All @@ -22,7 +22,8 @@ public void Test()
[Fact]
public void TestString()
{
ArgsToString("start end").Should().Be("start end");
// If we want two words without quotes, we need to pass them as two arguments
ArgsToString($"{"start"} {"end"}").Should().Be("start end");
ArgsToString("").Should().Be("");
ArgsToString(" ").Should().Be("");
}
Expand Down Expand Up @@ -61,6 +62,12 @@ public void TestAbsolutePathCollection()
ArgsToString($"start {paths:sn} end").Should().Be("start C:\\foo\\bar '/foo bar/foo' end");
}

[Fact]
public void TestSpacedPathOnly()
{
ArgsToString($"{(AbsolutePath)"C:" / "Program Files"}").Should().Be("\"C:\\Program Files\"");
}

[Fact]
public void TestFormat()
{
Expand All @@ -82,7 +89,8 @@ public void TestFormat()
[Fact]
public void TestUnquote()
{
ArgsToString($"{"start end"}").Should().Be("start end");
// If we want two words without quotes, we need to pass them as two arguments
ArgsToString($"{"start"} {"end"}").Should().Be("start end");
ArgsToString($"start {"spaced end"}").Should().Be("start \"spaced end\"");
ArgsToString($"{"spaced start"} end").Should().Be("\"spaced start\" end");
ArgsToString($"{"spaced start"} {"spaced end"}").Should().Be("\"spaced start\" \"spaced end\"");
Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.Tooling/ArgumentStringHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void AppendFormatted(IEnumerable<IAbsolutePathHolder> paths, int alignmen
public string ToStringAndClear()
{
var value = _builder.ToStringAndClear();
return value.Length > 1 && value.IndexOf(value: '"', startIndex: 1) == value.Length - 1
return value.Length > 1 && value.IndexOf(value: '"', startIndex: 1) == value.Length - 1 && value.IndexOf(' ') == -1
? value.TrimMatchingDoubleQuotes()
: value;
}
Expand Down
Loading