From a10b40341f994bcbacc7a4e89dd1376f5f7ffb6a Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 13 Mar 2026 18:30:43 +0000 Subject: [PATCH] fix: handle underscores in kebabToCamel flag key conversion Update kebabToCamel regex from '-(.)' to '[-_](.)' to handle both hyphens and underscores when converting flag keys to camelCase for React SDK instructions. SWITCH-1178 Co-Authored-By: jfong@launchdarkly.com --- internal/sdks/sdks.go | 6 +++--- internal/sdks/sdks_test.go | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/sdks/sdks.go b/internal/sdks/sdks.go index 289432c0..aed61604 100644 --- a/internal/sdks/sdks.go +++ b/internal/sdks/sdks.go @@ -46,10 +46,10 @@ func ReplaceSDKKeys(instructions string, sdkKey, clientSideId, mobileKey string) return r.Replace(instructions) } -// kebabToCamel converts a kebab-case key string into a camelCase key string, used for the React sdk instructions +// kebabToCamel converts a kebab-case or underscore-separated key string into a camelCase key string, used for the React sdk instructions func kebabToCamel(kebabCase string) string { - replaceDashRegex := regexp.MustCompile(`-(.)`) - camelCase := replaceDashRegex.ReplaceAllStringFunc(kebabCase, func(match string) string { + replaceSeparatorRegex := regexp.MustCompile(`[-_](.)`) + camelCase := replaceSeparatorRegex.ReplaceAllStringFunc(kebabCase, func(match string) string { return strings.ToUpper(string(match[1])) }) return camelCase diff --git a/internal/sdks/sdks_test.go b/internal/sdks/sdks_test.go index 08de2119..29ca8b59 100644 --- a/internal/sdks/sdks_test.go +++ b/internal/sdks/sdks_test.go @@ -34,6 +34,13 @@ func TestReplaceFlagKey(t *testing.T) { assert.Equal(t, string(tt.expected), string(updated)) }) } + + t.Run("replaces camelCase placeholder with underscore key converted to camelCase", func(t *testing.T) { + body := "# title ```const featureFlagKey = \"myFlagKey\"```" + expected := "# title ```const featureFlagKey = \"myCoolFlag\"```" + updated := sdks.ReplaceFlagKey(body, "my_cool_flag") + assert.Equal(t, expected, updated) + }) } func TestReplaceSDKKey(t *testing.T) {