@@ -15,7 +15,9 @@ import (
15
15
// using the -ldflags during compilation.
16
16
var Commit string
17
17
18
- // semanticAlphabet
18
+ // semanticAlphabet is the allowed characters from the semantic versioning
19
+ // guidelines for pre-release version and build metadata strings. In particular
20
+ // they MUST only contain characters in semanticAlphabet.
19
21
const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
20
22
21
23
// These constants define the application version and follow the semantic
@@ -63,11 +65,11 @@ func semanticVersion() string {
63
65
// Start with the major, minor, and patch versions.
64
66
version := fmt .Sprintf ("%d.%d.%d" , appMajor , appMinor , appPatch )
65
67
66
- // Append pre-release version if there is one. The hyphen called for
68
+ // Append pre-release version if there is one. The hyphen called for
67
69
// by the semantic versioning spec is automatically appended and should
68
- // not be contained in the pre-release string. The pre-release version
70
+ // not be contained in the pre-release string. The pre-release version
69
71
// is not appended if it contains invalid characters.
70
- preRelease := normalizeVerString (appPreRelease )
72
+ preRelease := normalizeVerString (appPreRelease , semanticAlphabet )
71
73
if preRelease != "" {
72
74
version = fmt .Sprintf ("%s-%s" , version , preRelease )
73
75
}
@@ -76,13 +78,11 @@ func semanticVersion() string {
76
78
}
77
79
78
80
// normalizeVerString returns the passed string stripped of all characters
79
- // which are not valid according to the semantic versioning guidelines for
80
- // pre-release version and build metadata strings. In particular they MUST
81
- // only contain characters in semanticAlphabet.
82
- func normalizeVerString (str string ) string {
81
+ // which are not valid according to the given alphabet.
82
+ func normalizeVerString (str , alphabet string ) string {
83
83
var result bytes.Buffer
84
84
for _ , r := range str {
85
- if strings .ContainsRune (semanticAlphabet , r ) {
85
+ if strings .ContainsRune (alphabet , r ) {
86
86
result .WriteRune (r )
87
87
}
88
88
}
0 commit comments