Skip to content

Commit 923af77

Browse files
committed
Quote GUIDs inline
1 parent 1556105 commit 923af77

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/MiniProfiler.Shared/SqlFormatters/InlineFormatter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public string GetParameterValue(SqlTimingParameter param)
7878
{
7979
case "string":
8080
case "datetime":
81+
case "guid":
8182
result = string.Format("'{0}'", result);
8283
break;
8384
case "boolean":

tests/MiniProfiler.Tests/SqlFormatterTests.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public class SqlFormatterTests
5454

5555
private const string None = "";
5656
private const string At = "@";
57-
public static IEnumerable<object[]> GetParamPrefixes()
57+
public static IEnumerable<TheoryDataRow<string>> GetParamPrefixes()
5858
{
59-
yield return new object[] { None };
60-
yield return new object[] { At };
59+
yield return new(None);
60+
yield return new(At);
6161
}
6262

6363
private static SqlCommand CreateDbCommand(CommandType commandType, string text)
@@ -100,6 +100,7 @@ public void InlineParameterNamesInParameterValues()
100100
var formatted = formatter.FormatSql(command, parameters);
101101
Assert.Equal("SELECT * FROM urls WHERE url = 'http://www.example.com?myid=1' OR myid = '1'", formatted);
102102
}
103+
103104
[Fact]
104105
public void InlineParameterValuesDisplayNullForStrings()
105106
{
@@ -148,6 +149,23 @@ public void InlineSpacesAfterCommasDisabled()
148149
Assert.Equal("SELECT myid,url FROM urls WHERE url = 'http://www.example.com?myid=1' OR myid = '1'", formatted);
149150
}
150151

152+
[Fact]
153+
public void InlineGuidsQuoted()
154+
{
155+
var formatter = new InlineFormatter()
156+
{
157+
InsertSpacesAfterCommas = false
158+
};
159+
var guid = Guid.NewGuid();
160+
var parameters = new List<SqlTimingParameter>
161+
{
162+
new SqlTimingParameter() { DbType = "guid", Name = "id", Value = guid.ToString() },
163+
};
164+
const string command = "SELECT 1 FROM urls WHERE id = @id";
165+
var formatted = formatter.FormatSql(command, parameters);
166+
Assert.Equal($"SELECT 1 FROM urls WHERE id = '{guid}'", formatted);
167+
}
168+
151169
[Fact]
152170
public void EnsureVerboseSqlServerFormatterOnlyAddsInformation()
153171
{

0 commit comments

Comments
 (0)