diff --git a/src/EFCore.Relational.Design/Internal/CSharpUtilities.cs b/src/EFCore.Relational.Design/Internal/CSharpUtilities.cs index c6ad110b540..a80e7c0ee23 100644 --- a/src/EFCore.Relational.Design/Internal/CSharpUtilities.cs +++ b/src/EFCore.Relational.Design/Internal/CSharpUtilities.cs @@ -118,7 +118,9 @@ public virtual string DelimitString([NotNull] string value) { Check.NotNull(value, nameof(value)); - return "\"" + EscapeString(value) + "\""; + return value.Contains(Environment.NewLine) + ? "@\"" + EscapeVerbatimString(value) + "\"" + : "\"" + EscapeString(value) + "\""; } /// diff --git a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpUtilitiesTest.cs b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpUtilitiesTest.cs index d562eb723c4..a2cd1a86383 100644 --- a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpUtilitiesTest.cs +++ b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpUtilitiesTest.cs @@ -23,5 +23,15 @@ public void GetTypeName(Type type, string typeName) } struct SomeGenericStruct {} + + [Theory] + [InlineData("", "\"\"")] + [InlineData("SomeValue", "\"SomeValue\"")] + [InlineData("Contains\\Backslash\"QuoteAnd\tTab", "\"Contains\\\\Backslash\\\"QuoteAnd\\tTab\"")] + [InlineData("Contains\r\nNewlinesAnd\"Quotes", "@\"Contains\r\nNewlinesAnd\"\"Quotes\"")] + public void DelimitString(string input, string expectedOutput) + { + Assert.Equal(expectedOutput, new CSharpUtilities().DelimitString(input)); + } } } \ No newline at end of file