• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gameap / gameap / 25833550014

14 May 2026 12:03AM UTC coverage: 76.64% (+0.2%) from 76.402%
25833550014

push

github

et-nik
lint fix

44892 of 58575 relevant lines covered (76.64%)

34171.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.48
/pkg/validation/string.go
1
package validation
2

3
import (
4
        "regexp"
5
        "slices"
6
        "strings"
7
)
8

9
// IsAlphanumeric checks if a string contains only lowercase letters (a-z) and digits (0-9).
10
// Returns true if the string is alphanumeric, false otherwise.
11
// Empty strings return false.
12
func IsAlphanumeric(s string) bool {
8✔
13
        if len(s) == 0 {
9✔
14
                return false
1✔
15
        }
1✔
16

17
        for _, ch := range s {
38✔
18
                if (ch < 'a' || ch > 'z') && (ch < '0' || ch > '9') {
35✔
19
                        return false
4✔
20
                }
4✔
21
        }
22

23
        return true
3✔
24
}
25

26
// IsAlphanumericMixed checks if a string contains only letters (a-z, A-Z) and digits (0-9).
27
// Returns true if the string is alphanumeric, false otherwise.
28
// Empty strings return false.
29
func IsAlphanumericMixed(s string) bool {
12✔
30
        if len(s) == 0 {
13✔
31
                return false
1✔
32
        }
1✔
33

34
        for _, ch := range s {
69✔
35
                if (ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9') {
62✔
36
                        return false
4✔
37
                }
4✔
38
        }
39

40
        return true
7✔
41
}
42

43
// IsSlug checks if a string contains only lowercase letters (a-z), digits (0-9), underscores (_), and hyphens (-).
44
// Returns true if the string is a valid slug, false otherwise.
45
// Empty strings return false.
46
func IsSlug(s string) bool {
14✔
47
        if len(s) == 0 {
15✔
48
                return false
1✔
49
        }
1✔
50

51
        for _, ch := range s {
86✔
52
                if (ch < 'a' || ch > 'z') && (ch < '0' || ch > '9') && ch != '_' && ch != '-' {
77✔
53
                        return false
4✔
54
                }
4✔
55
        }
56

57
        return true
9✔
58
}
59

60
var emailRegex = regexp.MustCompile(`^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`)
61

62
func IsEmail(s string) bool {
×
63
        return emailRegex.MatchString(s)
×
64
}
×
65

66
// IsRelativeServerPath reports whether s is a safe relative server directory:
67
// not anchored to a filesystem root, not a Windows drive path, and free of ".."
68
// segments. Used to reject inputs that would land on the daemon as an absolute
69
// path and trigger a double-join with the daemon's own work directory.
70
// Empty strings are not considered valid; callers that allow optional values
71
// should check emptiness separately.
72
func IsRelativeServerPath(s string) bool {
22✔
73
        if s == "" {
23✔
74
                return false
1✔
75
        }
1✔
76

77
        if s[0] == '/' || s[0] == '\\' {
24✔
78
                return false
3✔
79
        }
3✔
80

81
        if len(s) >= 2 && s[1] == ':' && IsASCIILetter(s[0]) {
21✔
82
                return false
3✔
83
        }
3✔
84

85
        normalized := strings.ReplaceAll(s, "\\", "/")
15✔
86

15✔
87
        return !slices.Contains(strings.Split(normalized, "/"), "..")
15✔
88
}
89

90
// IsASCIILetter reports whether c is an ASCII letter (a-z or A-Z).
91
func IsASCIILetter(c byte) bool {
77✔
92
        return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')
77✔
93
}
77✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc