Skip to content

Commit 0f9a154

Browse files
committedJan 3, 2025
thrift/thriftutil/enums: avoid duplicating underscores
1 parent 8599469 commit 0f9a154

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed
 

‎thrift/thriftutil/enums.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
func SanitizeCamelCaseThriftEnumValue(v string) string {
1010
if sks := strings.SplitN(v, "_", 2); len(sks) == 2 {
11-
return stringutil.CamelToSnakeCase(sks[1])
11+
return strings.ReplaceAll(stringutil.CamelToSnakeCase(sks[1]), "__", "_")
1212
}
1313

1414
return strings.ToLower(v)

‎thrift/thriftutil/enums_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func TestSanitizeCamelCaseThriftEnumValue(t *testing.T) {
1212
{"ContentType_InstagramMedia", "instagram_media"},
1313
{"ContentType_Unknown", "unknown"},
1414
{"regular string", "regular string"},
15+
{"MFAVector_RECOVERY_CODE", "recovery_code"},
1516
} {
1617
if out := SanitizeCamelCaseThriftEnumValue(tt.in); tt.out != out {
1718
t.Errorf("SanitizeCamelCaseThriftEnumValue(%q) = %q wanted: %q", tt.in, out, tt.out)

0 commit comments

Comments
 (0)