From d6e9d2cebb32fa4035fdcb089b850b0750573acf Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Tue, 17 May 2022 14:31:01 +0800 Subject: [PATCH] Add check fieldname format --- .../QueryableProvider/QueryableProvider.cs | 2 ++ .../SqlBuilderProvider/SqlBuilderProvider.cs | 2 +- .../SqlSugar/Utilities/DbExtensions.cs | 20 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index 9f6778ce3..353f37e82 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -735,6 +735,7 @@ namespace SqlSugar } public virtual ISugarQueryable OrderBy(string orderFileds) { + orderFileds = orderFileds.ToCheckField(); var orderByValue = QueryBuilder.OrderByValue; if (QueryBuilder.OrderByValue.IsNullOrEmpty()) { @@ -771,6 +772,7 @@ namespace SqlSugar public virtual ISugarQueryable GroupBy(string groupFileds) { + groupFileds = groupFileds.ToCheckField(); var croupByValue = QueryBuilder.GroupByValue; if (QueryBuilder.GroupByValue.IsNullOrEmpty()) { diff --git a/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs index a7c3db05e..5a3fcf213 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs @@ -160,7 +160,7 @@ namespace SqlSugar } string oldName = item.FieldName; item.FieldName = GetTranslationColumnName(item.FieldName); - Check.Exception(item.FieldName.Contains("--"), "Field name is error format"); + item.FieldName = item.FieldName.ToCheckField(); switch (item.ConditionalType) { case ConditionalType.Equal: diff --git a/Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs b/Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs index 7ac9fe2e6..83ae52529 100644 --- a/Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs +++ b/Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs @@ -47,6 +47,26 @@ namespace SqlSugar return value; } + /// + /// Check field format + /// + /// + /// + public static string ToCheckField(this string value) + { + if (value != null) + { + if (value.IsContainsIn(";", "--")) + { + throw new Exception($"{value} format error "); + } + else if (value.IsContainsIn("'")&&(value.Length- value.Replace("'","").Length)%2!=0) + { + throw new Exception($"{value} format error "); + } + } + return value; + } internal static string ToLower(this string value ,bool isAutoToLower) { if (value == null) return null;