Skip to content

Commit 41851dd

Browse files
authored
Disallow quotes in file-level directives (#51119)
1 parent cec531e commit 41851dd

16 files changed

+137
-18
lines changed

src/Cli/dotnet/Commands/CliCommandStrings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,9 @@ Tool '{1}' (version '{2}') was successfully installed. Entry is added to the man
16201620
<value>Duplicate directives are not supported: {0}</value>
16211621
<comment>{0} is the directive type and name.</comment>
16221622
</data>
1623+
<data name="QuoteInDirective" xml:space="preserve">
1624+
<value>Directives currently cannot contain double quotes (").</value>
1625+
</data>
16231626
<data name="InvalidOptionForStdin" xml:space="preserve">
16241627
<value>Cannot specify option '{0}' when also using '-' to read the file from standard input.</value>
16251628
<comment>{0} is an option name like '--no-build'.</comment>

src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,8 +1505,15 @@ public static ImmutableArray<CSharpDirective> FindDirectives(SourceFile sourceFi
15051505
Diagnostics = diagnostics,
15061506
SourceFile = sourceFile,
15071507
DirectiveKind = name.ToString(),
1508-
DirectiveText = value.ToString()
1508+
DirectiveText = value.ToString(),
15091509
};
1510+
1511+
// Block quotes now so we can later support quoted values without a breaking change. https://github.com/dotnet/sdk/issues/49367
1512+
if (value.Contains('"'))
1513+
{
1514+
diagnostics.AddError(sourceFile, context.Info.Span, CliCommandStrings.QuoteInDirective);
1515+
}
1516+
15101517
if (CSharpDirective.Parse(context) is { } directive)
15111518
{
15121519
// If the directive is already present, report an error.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)