ソースを参照

新增防止sql注入

dcsunny 2 年 前
コミット
06883ee7ae
1 ファイル変更10 行追加2 行削除
  1. 10 2
      common/sql.go

+ 10 - 2
common/sql.go

@@ -2,10 +2,18 @@ package common
 
 import "strings"
 
-// SqlStrReplace 防止sql注入
-func SqlStrReplace(str string) string {
+// SqlStrReplaceSingleQuotes 防止sql注入 单引号
+func SqlStrReplaceSingleQuotes(str string) string {
 	if strings.Contains(str, "'") {
 		str = strings.Replace(str, "'", "\\'", -1)
 	}
 	return str
 }
+
+// SqlStrReplaceDoubleQuotes 防止sql注入 双引号
+func SqlStrReplaceDoubleQuotes(str string) string {
+	if strings.Contains(str, "\"") {
+		str = strings.Replace(str, "\"", "\\\"", -1)
+	}
+	return str
+}