Skip to content

Commit e6e533a

Browse files
committed
version: allow specifying the normalization alphabet
1 parent 58c1c25 commit e6e533a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

version.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import (
1515
// using the -ldflags during compilation.
1616
var Commit string
1717

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.
1921
const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
2022

2123
// These constants define the application version and follow the semantic
@@ -63,11 +65,11 @@ func semanticVersion() string {
6365
// Start with the major, minor, and patch versions.
6466
version := fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch)
6567

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
6769
// 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
6971
// is not appended if it contains invalid characters.
70-
preRelease := normalizeVerString(appPreRelease)
72+
preRelease := normalizeVerString(appPreRelease, semanticAlphabet)
7173
if preRelease != "" {
7274
version = fmt.Sprintf("%s-%s", version, preRelease)
7375
}
@@ -76,13 +78,11 @@ func semanticVersion() string {
7678
}
7779

7880
// 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 {
8383
var result bytes.Buffer
8484
for _, r := range str {
85-
if strings.ContainsRune(semanticAlphabet, r) {
85+
if strings.ContainsRune(alphabet, r) {
8686
result.WriteRune(r)
8787
}
8888
}

0 commit comments

Comments
 (0)