Skip to content

Commit c82d079

Browse files
committed
version: narrow alphabet of acceptable version string field characters
This commit narrows the field of acceptable characters to 0-9 and a-z. The alphabet is compliant with SemVer but also stricter.
1 parent 6114235 commit c82d079

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

version.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ var (
3131
GoVersion string
3232
)
3333

34-
// semanticAlphabet is the set of characters that are permitted for use in
35-
// AppStatus and AppPreRelease.
36-
const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
34+
// versionFieldsAlphabet is the set of characters that are permitted for use in
35+
// a version string field.
36+
const versionFieldsAlphabet = "0123456789abcdefghijklmnopqrstuvwxyz"
3737

3838
// These constants define the application version and follow the semantic
3939
// versioning 2.0.0 spec (http://semver.org/).
@@ -78,7 +78,7 @@ var agentName = defaultAgentName
7878
// the software tapd is bundled in (for example LiT). This function panics if
7979
// the agent name contains characters outside of the allowed semantic alphabet.
8080
func SetAgentName(newAgentName string) {
81-
agentNameAlphabet := semanticAlphabet + "-. "
81+
agentNameAlphabet := versionFieldsAlphabet + "-. "
8282

8383
for _, r := range newAgentName {
8484
if !strings.ContainsRune(agentNameAlphabet, r) {
@@ -95,7 +95,7 @@ func SetAgentName(newAgentName string) {
9595
func UserAgent(initiator string) string {
9696
// We'll only allow "safe" characters in the initiator portion of the
9797
// user agent string and spaces only if surrounded by other characters.
98-
initiatorAlphabet := semanticAlphabet + "-. "
98+
initiatorAlphabet := versionFieldsAlphabet + "-. "
9999
cleanInitiator := normalizeVerString(
100100
strings.TrimSpace(initiator), initiatorAlphabet,
101101
)
@@ -120,9 +120,9 @@ func UserAgent(initiator string) string {
120120
func init() {
121121
// Assert that AppStatus is valid according to the semantic versioning
122122
// guidelines for pre-release version and build metadata strings. In
123-
// particular, it MUST only contain characters in semanticAlphabet.
123+
// particular, it MUST only contain characters in versionFieldsAlphabet.
124124
for _, r := range AppStatus {
125-
if !strings.ContainsRune(semanticAlphabet, r) {
125+
if !strings.ContainsRune(versionFieldsAlphabet, r) {
126126
panic(fmt.Errorf("rune: %v is not in the semantic "+
127127
"alphabet", r))
128128
}
@@ -131,9 +131,9 @@ func init() {
131131
// Assert that AppPreRelease is valid according to the semantic
132132
// versioning guidelines for pre-release version and build metadata
133133
// strings. In particular, it MUST only contain characters in
134-
// semanticAlphabet.
134+
// versionFieldsAlphabet.
135135
for _, r := range AppPreRelease {
136-
if !strings.ContainsRune(semanticAlphabet, r) {
136+
if !strings.ContainsRune(versionFieldsAlphabet, r) {
137137
panic(fmt.Errorf("rune: %v is not in the semantic "+
138138
"alphabet", r))
139139
}
@@ -190,14 +190,14 @@ func semanticVersion() string {
190190
// hyphen called for by the semantic versioning spec is automatically
191191
// appended and should not be contained in the status string. The status
192192
// is not appended if it contains invalid characters.
193-
appStatus := normalizeVerString(AppStatus, semanticAlphabet)
193+
appStatus := normalizeVerString(AppStatus, versionFieldsAlphabet)
194194

195195
// If defined, we will now sanitise the pre-release version string. The
196196
// hyphen called for by the semantic versioning spec is automatically
197197
// appended and should not be contained in the pre-release string.
198198
// The pre-release version is not appended if it contains invalid
199199
// characters.
200-
preRelease := normalizeVerString(AppPreRelease, semanticAlphabet)
200+
preRelease := normalizeVerString(AppPreRelease, versionFieldsAlphabet)
201201

202202
// Append any status and pre-release strings to the version string.
203203
switch {

0 commit comments

Comments
 (0)