Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit d329d33

Browse files
committed
Exclude MySql '`' quotes when verifying illegal tokens
1 parent 7e581a5 commit d329d33

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/ServiceStack.OrmLite/OrmLiteUtilExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ public static string SqlVerifyFragment(this string sqlFragment, IEnumerable<stri
186186
var fragmentToVerify = sqlFragment
187187
.StripQuotedStrings('\'')
188188
.StripQuotedStrings('"')
189+
.StripQuotedStrings('`')
189190
.ToLower();
190191

191192
foreach (var illegalFragment in illegalFragments)

tests/ServiceStack.OrmLite.Tests/SqlFormatTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using NUnit.Framework;
4+
using ServiceStack.DataAnnotations;
45
using ServiceStack.Text;
56

67
namespace ServiceStack.OrmLite.Tests
@@ -73,5 +74,20 @@ public void SqlParam_sanitizes_param_values()
7374
Assert.That("' or Field LIKE '%".SqlParam(), Is.EqualTo("'' or Field LIKE ''%"));
7475
}
7576

77+
[Alias("profile_extended")]
78+
public class ProflieExtended
79+
{
80+
public int Id { get; set; }
81+
}
82+
83+
[Test]
84+
public void Does_allow_illegal_tokens_in_MySql_table_names()
85+
{
86+
var sql = MySqlDialect.Provider.ToSelectStatement(typeof(ProflieExtended), "1 = 1")
87+
.Replace("SELECT ","");
88+
Assert.That(sql, Is.EqualTo("`Id` FROM `profile_extended` WHERE 1 = 1"));
89+
90+
sql.SqlVerifyFragment();
91+
}
7692
}
7793
}

0 commit comments

Comments
 (0)