-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuzzer.go
79 lines (73 loc) · 1.71 KB
/
fuzzer.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
package fuzzer
import (
"fmt"
"strings"
)
type fuzzer struct {
fns map[string]func(args ...string) string // contains user defined functions, during parsing the tag contents will be split on semicolons to generate the function args
}
func (f *fuzzer) process(str string) string {
if str == "" {
return str
}
tokens := f.tokenize(str)
var parsed strings.Builder
for _, t := range tokens {
var result string
switch tt := t.(type) {
case tUserFn:
result = f.process(tt.parse())
case tMemory:
result = f.process(tt.parse())
case tFloat:
result = tt.parse()
case tFloatRange:
result = tt.parse()
case tInt:
result = tt.parse()
case tIntRange:
result = tt.parse()
case tIntList:
result = tt.parse()
case tHash:
result = tt.parse()
case tUUID:
result = tt.parse()
case tStrFromList:
result = tt.parse()
case tStrLower:
result = tt.parse()
case tStrUpper:
result = tt.parse()
case tStr:
result = tt.parse()
case tAlphaLower:
result = tt.parse()
case tAlphaUpper:
result = tt.parse()
case tAlpha:
result = tt.parse()
case tAny:
result = fmt.Sprint(tt)
for strings.Count(result, tknStart) > 0 {
if strings.Count(result, tknStart) != strings.Count(result, tknEnd) {
result = "" // Don't include unparsed tokens
break
}
if strings.Count(result, tknStart) > 1 {
// Solve nested tokens first
result = "[" + f.process(result[1:len(result)-1]) + "]"
continue
}
// Process the outermost token
result = f.process(result)
}
case tUnknown:
result = "" // Don't include unparsed tokens
default:
result = fmt.Sprint(tt)
}
parsed.WriteString(result)
}
return strings.Trim(parsed.String(), " \r\n")
}