Skip to content
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
12 changes: 10 additions & 2 deletions src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1738,12 +1738,20 @@ private static (string, string?)? ParseOptionalTwoParts(in ParseContext context,
return context.Diagnostics.AddError<(string, string?)?>(context.SourceFile, context.Info.Span, string.Format(CliCommandStrings.InvalidDirectiveName, directiveKind, separator));
}

var secondPart = i < 0 ? [] : context.DirectiveText.AsSpan((i + 1)..).TrimStart();
if (i < 0 || secondPart.IsWhiteSpace())
if (i < 0)
{
return (firstPart.ToString(), null);
}

var secondPart = context.DirectiveText.AsSpan((i + 1)..).TrimStart();
if (secondPart.IsWhiteSpace())
{
Debug.Assert(secondPart.Length == 0,
"We have trimmed the second part, so if it's white space, it should be actually empty.");

return (firstPart.ToString(), string.Empty);
}

return (firstPart.ToString(), secondPart.ToString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,50 @@ public void Directives_EmptyName(
expectedWildcardPattern: RunFileTests.DirectiveError("/app/Program.cs", 1, CliCommandStrings.MissingDirectiveName, directive));
}

[Theory]
[InlineData("")]
[InlineData(" ")]
public void Directives_EmptyValue(string value)
{
VerifyConversion(
inputCSharp: $"""
#:property TargetFramework={value}
#:property Prop1={value}
#:sdk First@{value}
#:sdk Second@{value}
#:package P1@{value}
""",
expectedProject: """
<Project Sdk="First/">

<Sdk Name="Second" Version="" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<PackAsTool>true</PackAsTool>
<TargetFramework></TargetFramework>
<Prop1></Prop1>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="P1" Version="" />
</ItemGroup>

</Project>

""",
expectedCSharp: "");

VerifyConversionThrows(
inputCSharp: $"""
#:project{value}
""",
expectedWildcardPattern: RunFileTests.DirectiveError("/app/Program.cs", 1, CliCommandStrings.MissingDirectiveName, "project"));
}

[Fact]
public void Directives_MissingPropertyValue()
{
Expand Down
Loading