Skip to content

Commit

Permalink
Update Scaffolding to escape a string containing newlines as a verbat…
Browse files Browse the repository at this point in the history
…im string.
  • Loading branch information
lajones committed Apr 13, 2017
1 parent 0748e3e commit cdd23ff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/EFCore.Relational.Design/Internal/CSharpUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) + "\"";
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,15 @@ public void GetTypeName(Type type, string typeName)
}

struct SomeGenericStruct<T> {}

[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));
}
}
}

0 comments on commit cdd23ff

Please sign in to comment.