-
Notifications
You must be signed in to change notification settings - Fork 5
/
validators.go
97 lines (83 loc) · 2.18 KB
/
validators.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"regexp"
"strings"
)
func stringInSlice(str string, list []string) bool {
for _, v := range list {
if v == str {
return true
}
}
return false
}
func isGitRange(input string) bool {
r := regexp.MustCompile("[0-9a-f]{3,}\\.\\.[0-9a-f]{3,}")
return r.Match([]byte(input))
}
func isGitPath(input string) bool {
r := regexp.MustCompile("^[ab]/")
return r.Match([]byte(input))
}
func isEmail(input string) bool {
r := regexp.MustCompile("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+.)+([a-zA-Z]{2,4})")
result := r.FindSubmatch([]byte(input))
if result == nil {
return false
}
fileExtensions := []string{"png", "bmp", "jpeg"}
return !stringInSlice(string(result[1]), fileExtensions)
}
func isDate(input string) bool {
r := regexp.MustCompile("^[0-9]+/[0-9]+/[0-9]+")
return r.Match([]byte(input))
}
func isGitInstruction(input string) bool {
r := regexp.MustCompile("\\.{3,}")
return r.Match([]byte(input))
}
func replaceGitPath(input string) string {
r := regexp.MustCompile("^[ab]/(.*)")
temp := [][]byte{}
temp = r.FindSubmatch([]byte(input))
return string(temp[1])
}
func isIp(input string) bool {
r := regexp.MustCompile("^[0-9]{1,3}\\.[0-9x]{1,3}\\.[0-9x]{1,3}\\.[0-9x]{1,3}$")
return r.Match([]byte(input))
}
func isVersion(input string) bool {
r := regexp.MustCompile("^v?[0-9x]{1,3}\\.[0-9x]{1,3}(\\.[0-9x]{1,3})?$")
return r.Match([]byte(input))
}
func isSpace(input string) bool {
r := regexp.MustCompile("^[0-9]*\\.[0-9]+[MGK]$")
return r.Match([]byte(input))
}
func startsWithInvalidString(input string) bool {
invalidBeginnings := []string{"Error/", "Object.", "Array."}
for _, s := range invalidBeginnings {
if strings.Index(input, s) == 0 {
return true
}
}
return false
}
func endsWithInvalidString(input string) bool {
invalidEndings := []string{"."}
for _, s := range invalidEndings {
if strings.LastIndex(input, s) == len(input)-len(s) {
return true
}
}
return false
}
func containsInvalidString(input string) bool {
invalidStrings := []string{"//", "()", "and/or", "remotes/", "origin/", "{", "}", "<", ">", "$", "*", "this."}
for _, s := range invalidStrings {
if strings.Contains(input, s) {
return true
}
}
return false
}