Browse Source

Update checkfiled

pull/40/head
sunkaixuan 1 year ago
parent
commit
a603f4e276
  1. 32
      Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs

32
Src/Asp.Net/SqlSugar/Utilities/DbExtensions.cs

@ -72,31 +72,45 @@ namespace SqlSugar
{
throw new Exception($"{value} format error ");
}
else if (value.IsContainsIn("'")&&(value.Length- value.Replace("'","").Length)%2!=0)
else if (value.IsContainsIn("'") && (value.Length - value.Replace("'", "").Length) % 2 != 0)
{
throw new Exception($"{value} format error ");
}
else if (value.ToLower().Contains("/update/")
|| value.ToLower().Contains("/delete/")
|| value.ToLower().Contains("/drop/")
|| value.ToLower().Contains("/alert/")
|| value.ToLower().Contains("/create/")
|| value.ToLower().Contains("/insert/"))
else if (IsUpdateSql(value,"/","/"))
{
Check.ExceptionEasy($"{value} format error ", value + "不能存在 /+【update drop 等】+/ ");
}
else if (value.ToLower().Contains(" update ")
else if (IsUpdateSql(value, "/", " "))
{
Check.ExceptionEasy($"{value} format error ", value + "不能存在 /+【update drop 等】+空格 ");
}
else if (IsUpdateSql(value, " ", "/"))
{
Check.ExceptionEasy($"{value} format error ", value + "不能存在 空格+【update drop 等】+/ ");
}
else if (value.ToLower().Contains(" update ")
|| value.ToLower().Contains(" delete ")
|| value.ToLower().Contains(" drop ")
|| value.ToLower().Contains(" alert ")
|| value.ToLower().Contains(" create ")
|| value.ToLower().Contains(" insert "))
{
Check.ExceptionEasy($"{value} format error ", value+ "不能存在 空格+【update drop 等】+空格 ");
Check.ExceptionEasy($"{value} format error ", value + "不能存在 空格+【update drop 等】+空格 ");
}
}
return value;
}
private static bool IsUpdateSql(string value,string left ,string right)
{
return value.ToLower().Contains(left+"update"+right)
|| value.ToLower().Contains(left + "delete" + right)
|| value.ToLower().Contains(left + "drop" + right)
|| value.ToLower().Contains(left + "alert" + right)
|| value.ToLower().Contains(left + "create" + right)
|| value.ToLower().Contains(left + "insert" + right);
}
public static string ToCheckRegexW(this string value)
{
if (Regex.IsMatch(value,@"^\w+$"))

Loading…
Cancel
Save