-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make newline escaping logic more robust
Fixes #22553
- Loading branch information
Showing
6 changed files
with
330 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
test/EFCore.SqlServer.Tests/Storage/SqlServerStringTypeMappingTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Xunit; | ||
|
||
namespace Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal | ||
{ | ||
public class SqlServerStringTypeMappingTest | ||
{ | ||
[ConditionalTheory] | ||
[InlineData("", "''")] | ||
[InlineData("'Sup", "'''Sup'")] | ||
[InlineData("I'm", "'I''m'")] | ||
[InlineData("lovin'", "'lovin'''")] | ||
[InlineData("it", "'it'")] | ||
[InlineData("'", "''''")] | ||
[InlineData("''", "''''''")] | ||
[InlineData("I'm lovin'", "'I''m lovin'''")] | ||
[InlineData("I'm lovin' it", "'I''m lovin'' it'")] | ||
[InlineData("\r", "CHAR(13)")] | ||
[InlineData("\n", "CHAR(10)")] | ||
[InlineData("\r\n", "CONCAT(CHAR(13), CHAR(10))")] | ||
[InlineData("\n'sup", "CONCAT(CHAR(10), '''sup')")] | ||
[InlineData("I'm\n", "CONCAT('I''m', CHAR(10))")] | ||
[InlineData("lovin'\n", "CONCAT('lovin''', CHAR(10))")] | ||
[InlineData("it\n", "CONCAT('it', CHAR(10))")] | ||
[InlineData("\nit", "CONCAT(CHAR(10), 'it')")] | ||
[InlineData("'\n", "CONCAT('''', CHAR(10))")] | ||
public void GenerateProviderValueSqlLiteral_works(string value, string expected) | ||
{ | ||
var mapping = new SqlServerStringTypeMapping("varchar(max)"); | ||
Assert.Equal(expected, mapping.GenerateProviderValueSqlLiteral(value)); | ||
} | ||
|
||
[ConditionalTheory] | ||
[InlineData("", "N''")] | ||
[InlineData("'Sup", "N'''Sup'")] | ||
[InlineData("I'm", "N'I''m'")] | ||
[InlineData("lovin'", "N'lovin'''")] | ||
[InlineData("it", "N'it'")] | ||
[InlineData("'", "N''''")] | ||
[InlineData("''", "N''''''")] | ||
[InlineData("I'm lovin'", "N'I''m lovin'''")] | ||
[InlineData("I'm lovin' it", "N'I''m lovin'' it'")] | ||
[InlineData("\r", "NCHAR(13)")] | ||
[InlineData("\n", "NCHAR(10)")] | ||
[InlineData("\r\n", "CONCAT(NCHAR(13), NCHAR(10))")] | ||
[InlineData("\n'sup", "CONCAT(NCHAR(10), N'''sup')")] | ||
[InlineData("I'm\n", "CONCAT(N'I''m', NCHAR(10))")] | ||
[InlineData("lovin'\n", "CONCAT(N'lovin''', NCHAR(10))")] | ||
[InlineData("it\n", "CONCAT(N'it', NCHAR(10))")] | ||
[InlineData("\nit", "CONCAT(NCHAR(10), N'it')")] | ||
[InlineData("'\n", "CONCAT(N'''', NCHAR(10))")] | ||
public void GenerateProviderValueSqlLiteral_works_unicode(string value, string expected) | ||
{ | ||
var mapping = new SqlServerStringTypeMapping("nvarchar(max)", unicode: true); | ||
Assert.Equal(expected, mapping.GenerateProviderValueSqlLiteral(value)); | ||
} | ||
} | ||
} |
Oops, something went wrong.