소스 검색

新增防止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
+}