mirror of
https://github.com/astaxie/beego.git
synced 2024-12-25 13:30:49 +00:00
fix gosimple
This commit is contained in:
parent
3c9b6c99b7
commit
69f0b94745
@ -53,21 +53,21 @@ func Substr(s string, start, length int) string {
|
||||
// HTML2str returns escaping text convert from html.
|
||||
func HTML2str(html string) string {
|
||||
|
||||
re, _ := regexp.Compile("\\<[\\S\\s]+?\\>")
|
||||
re, _ := regexp.Compile(`\<[\S\s]+?\>`)
|
||||
html = re.ReplaceAllStringFunc(html, strings.ToLower)
|
||||
|
||||
//remove STYLE
|
||||
re, _ = regexp.Compile("\\<style[\\S\\s]+?\\</style\\>")
|
||||
re, _ = regexp.Compile(`\<style[\S\s]+?\</style\>`)
|
||||
html = re.ReplaceAllString(html, "")
|
||||
|
||||
//remove SCRIPT
|
||||
re, _ = regexp.Compile("\\<script[\\S\\s]+?\\</script\\>")
|
||||
re, _ = regexp.Compile(`\<script[\S\s]+?\</script\>`)
|
||||
html = re.ReplaceAllString(html, "")
|
||||
|
||||
re, _ = regexp.Compile("\\<[\\S\\s]+?\\>")
|
||||
re, _ = regexp.Compile(`\<[\S\s]+?\>`)
|
||||
html = re.ReplaceAllString(html, "\n")
|
||||
|
||||
re, _ = regexp.Compile("\\s{2,}")
|
||||
re, _ = regexp.Compile(`\s{2,}`)
|
||||
html = re.ReplaceAllString(html, "\n")
|
||||
|
||||
return strings.TrimSpace(html)
|
||||
|
@ -175,10 +175,10 @@ func TestAlphaNumeric(t *testing.T) {
|
||||
func TestMatch(t *testing.T) {
|
||||
valid := Validation{}
|
||||
|
||||
if valid.Match("suchuangji@gmail", regexp.MustCompile("^\\w+@\\w+\\.\\w+$"), "match").Ok {
|
||||
if valid.Match("suchuangji@gmail", regexp.MustCompile(`^\w+@\w+\.\w+$`), "match").Ok {
|
||||
t.Error("\"suchuangji@gmail\" match \"^\\w+@\\w+\\.\\w+$\" should be false")
|
||||
}
|
||||
if !valid.Match("suchuangji@gmail.com", regexp.MustCompile("^\\w+@\\w+\\.\\w+$"), "match").Ok {
|
||||
if !valid.Match("suchuangji@gmail.com", regexp.MustCompile(`^\w+@\w+\.\w+$`), "match").Ok {
|
||||
t.Error("\"suchuangji@gmail\" match \"^\\w+@\\w+\\.\\w+$\" should be true")
|
||||
}
|
||||
}
|
||||
@ -186,10 +186,10 @@ func TestMatch(t *testing.T) {
|
||||
func TestNoMatch(t *testing.T) {
|
||||
valid := Validation{}
|
||||
|
||||
if valid.NoMatch("123@gmail", regexp.MustCompile("[^\\w\\d]"), "nomatch").Ok {
|
||||
if valid.NoMatch("123@gmail", regexp.MustCompile(`[^\w\d]`), "nomatch").Ok {
|
||||
t.Error("\"123@gmail\" not match \"[^\\w\\d]\" should be false")
|
||||
}
|
||||
if !valid.NoMatch("123gmail", regexp.MustCompile("[^\\w\\d]"), "match").Ok {
|
||||
if !valid.NoMatch("123gmail", regexp.MustCompile(`[^\w\d]`), "match").Ok {
|
||||
t.Error("\"123@gmail\" not match \"[^\\w\\d@]\" should be true")
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ func (r Required) IsSatisfied(obj interface{}) bool {
|
||||
|
||||
// DefaultMessage return the default error message
|
||||
func (r Required) DefaultMessage() string {
|
||||
return fmt.Sprint(MessageTmpls["Required"])
|
||||
return MessageTmpls["Required"]
|
||||
}
|
||||
|
||||
// GetKey return the r.Key
|
||||
@ -364,7 +364,7 @@ func (a Alpha) IsSatisfied(obj interface{}) bool {
|
||||
|
||||
// DefaultMessage return the default Length error message
|
||||
func (a Alpha) DefaultMessage() string {
|
||||
return fmt.Sprint(MessageTmpls["Alpha"])
|
||||
return MessageTmpls["Alpha"]
|
||||
}
|
||||
|
||||
// GetKey return the m.Key
|
||||
@ -397,7 +397,7 @@ func (n Numeric) IsSatisfied(obj interface{}) bool {
|
||||
|
||||
// DefaultMessage return the default Length error message
|
||||
func (n Numeric) DefaultMessage() string {
|
||||
return fmt.Sprint(MessageTmpls["Numeric"])
|
||||
return MessageTmpls["Numeric"]
|
||||
}
|
||||
|
||||
// GetKey return the n.Key
|
||||
@ -430,7 +430,7 @@ func (a AlphaNumeric) IsSatisfied(obj interface{}) bool {
|
||||
|
||||
// DefaultMessage return the default Length error message
|
||||
func (a AlphaNumeric) DefaultMessage() string {
|
||||
return fmt.Sprint(MessageTmpls["AlphaNumeric"])
|
||||
return MessageTmpls["AlphaNumeric"]
|
||||
}
|
||||
|
||||
// GetKey return the a.Key
|
||||
@ -495,7 +495,7 @@ func (n NoMatch) GetLimitValue() interface{} {
|
||||
return n.Regexp.String()
|
||||
}
|
||||
|
||||
var alphaDashPattern = regexp.MustCompile("[^\\d\\w-_]")
|
||||
var alphaDashPattern = regexp.MustCompile(`[^\d\w-_]`)
|
||||
|
||||
// AlphaDash check not Alpha
|
||||
type AlphaDash struct {
|
||||
@ -505,7 +505,7 @@ type AlphaDash struct {
|
||||
|
||||
// DefaultMessage return the default AlphaDash error message
|
||||
func (a AlphaDash) DefaultMessage() string {
|
||||
return fmt.Sprint(MessageTmpls["AlphaDash"])
|
||||
return MessageTmpls["AlphaDash"]
|
||||
}
|
||||
|
||||
// GetKey return the n.Key
|
||||
@ -518,7 +518,7 @@ func (a AlphaDash) GetLimitValue() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
var emailPattern = regexp.MustCompile("^[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[a-zA-Z0-9](?:[\\w-]*[\\w])?$")
|
||||
var emailPattern = regexp.MustCompile(`^[\w!#$%&'*+/=?^_` + "`" + `{|}~-]+(?:\.[\w!#$%&'*+/=?^_` + "`" + `{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[a-zA-Z0-9](?:[\w-]*[\w])?$`)
|
||||
|
||||
// Email check struct
|
||||
type Email struct {
|
||||
@ -528,7 +528,7 @@ type Email struct {
|
||||
|
||||
// DefaultMessage return the default Email error message
|
||||
func (e Email) DefaultMessage() string {
|
||||
return fmt.Sprint(MessageTmpls["Email"])
|
||||
return MessageTmpls["Email"]
|
||||
}
|
||||
|
||||
// GetKey return the n.Key
|
||||
@ -541,7 +541,7 @@ func (e Email) GetLimitValue() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
var ipPattern = regexp.MustCompile("^((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)$")
|
||||
var ipPattern = regexp.MustCompile(`^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$`)
|
||||
|
||||
// IP check struct
|
||||
type IP struct {
|
||||
@ -551,7 +551,7 @@ type IP struct {
|
||||
|
||||
// DefaultMessage return the default IP error message
|
||||
func (i IP) DefaultMessage() string {
|
||||
return fmt.Sprint(MessageTmpls["IP"])
|
||||
return MessageTmpls["IP"]
|
||||
}
|
||||
|
||||
// GetKey return the i.Key
|
||||
@ -564,7 +564,7 @@ func (i IP) GetLimitValue() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
var base64Pattern = regexp.MustCompile("^(?:[A-Za-z0-99+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$")
|
||||
var base64Pattern = regexp.MustCompile(`^(?:[A-Za-z0-99+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$`)
|
||||
|
||||
// Base64 check struct
|
||||
type Base64 struct {
|
||||
@ -574,7 +574,7 @@ type Base64 struct {
|
||||
|
||||
// DefaultMessage return the default Base64 error message
|
||||
func (b Base64) DefaultMessage() string {
|
||||
return fmt.Sprint(MessageTmpls["Base64"])
|
||||
return MessageTmpls["Base64"]
|
||||
}
|
||||
|
||||
// GetKey return the b.Key
|
||||
@ -588,7 +588,7 @@ func (b Base64) GetLimitValue() interface{} {
|
||||
}
|
||||
|
||||
// just for chinese mobile phone number
|
||||
var mobilePattern = regexp.MustCompile("^((\\+86)|(86))?(1(([35][0-9])|[8][0-9]|[7][06789]|[4][579]))\\d{8}$")
|
||||
var mobilePattern = regexp.MustCompile(`^((\+86)|(86))?(1(([35][0-9])|[8][0-9]|[7][06789]|[4][579]))\d{8}$`)
|
||||
|
||||
// Mobile check struct
|
||||
type Mobile struct {
|
||||
@ -598,7 +598,7 @@ type Mobile struct {
|
||||
|
||||
// DefaultMessage return the default Mobile error message
|
||||
func (m Mobile) DefaultMessage() string {
|
||||
return fmt.Sprint(MessageTmpls["Mobile"])
|
||||
return MessageTmpls["Mobile"]
|
||||
}
|
||||
|
||||
// GetKey return the m.Key
|
||||
@ -612,7 +612,7 @@ func (m Mobile) GetLimitValue() interface{} {
|
||||
}
|
||||
|
||||
// just for chinese telephone number
|
||||
var telPattern = regexp.MustCompile("^(0\\d{2,3}(\\-)?)?\\d{7,8}$")
|
||||
var telPattern = regexp.MustCompile(`^(0\d{2,3}(\-)?)?\d{7,8}$`)
|
||||
|
||||
// Tel check telephone struct
|
||||
type Tel struct {
|
||||
@ -622,7 +622,7 @@ type Tel struct {
|
||||
|
||||
// DefaultMessage return the default Tel error message
|
||||
func (t Tel) DefaultMessage() string {
|
||||
return fmt.Sprint(MessageTmpls["Tel"])
|
||||
return MessageTmpls["Tel"]
|
||||
}
|
||||
|
||||
// GetKey return the t.Key
|
||||
@ -649,7 +649,7 @@ func (p Phone) IsSatisfied(obj interface{}) bool {
|
||||
|
||||
// DefaultMessage return the default Phone error message
|
||||
func (p Phone) DefaultMessage() string {
|
||||
return fmt.Sprint(MessageTmpls["Phone"])
|
||||
return MessageTmpls["Phone"]
|
||||
}
|
||||
|
||||
// GetKey return the p.Key
|
||||
@ -663,7 +663,7 @@ func (p Phone) GetLimitValue() interface{} {
|
||||
}
|
||||
|
||||
// just for chinese zipcode
|
||||
var zipCodePattern = regexp.MustCompile("^[1-9]\\d{5}$")
|
||||
var zipCodePattern = regexp.MustCompile(`^[1-9]\d{5}$`)
|
||||
|
||||
// ZipCode check the zip struct
|
||||
type ZipCode struct {
|
||||
@ -673,7 +673,7 @@ type ZipCode struct {
|
||||
|
||||
// DefaultMessage return the default Zip error message
|
||||
func (z ZipCode) DefaultMessage() string {
|
||||
return fmt.Sprint(MessageTmpls["ZipCode"])
|
||||
return MessageTmpls["ZipCode"]
|
||||
}
|
||||
|
||||
// GetKey return the z.Key
|
||||
|
Loading…
Reference in New Issue
Block a user