Repository navigation
fix: camelToKebab keeps underscores and non-ASCII letters readable - #42
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #42 +/- ##
==========================================
+ Coverage 95.72% 96.09% +0.37%
==========================================
Files 20 20
Lines 1870 1869 -1
==========================================
+ Hits 1790 1796 +6
+ Misses 48 43 -5
+ Partials 32 30 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
camelToKebab lowercased every rune with r | 0x20, which is only right for
ASCII capitals. An underscore (0x5F) became DEL (0x7F), so a page field
or component named Row_Edit got the id "row\x7f-edit", and letters
outside Latin-1 were garbled ("Größe" became "gröÿe"). It also compared
bytes, not runes, around multi-byte letters.
It now walks runes and lowercases with unicode.ToLower, finding word
starts with unicode.IsUpper/IsLower. Underscores and hyphens separate
words: "Row_Edit" and "row_edit" become "row-edit", and a hyphenated
import path element such as "ui-Kit" becomes "ui-kit" rather than
"ui--kit". Hyphens never repeat or start or end the result.
Ids of names made of ASCII letters and digits are unchanged, checked
against the old function over 100,000 random names. Ids change only for
names with underscores, non-ASCII letters, or a function's package path
element with leading, trailing or doubled hyphens or a hyphen before a
capital. Two names that now kebab-case alike on one tree (RowEdit and
Row_Edit) are reported by Mount's id uniqueness check.
idSegment, which #41 added to collapse hyphen runs after camelToKebab,
is now camelToKebab itself and is removed.
jackielii
force-pushed
the
fix/kebab-separators
branch
from
October 29, 2026 20:43
4f01c3a to
8562fb1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
camelToKebablowercased every rune withr | 0x20, which is only correct for ASCII capitals:Row_Editrow\x7f-edit(DEL control character)row-editrow_editrow\x7feditrow-editGrößegröÿegrößepageÜberpageüberpage-überui-Kit(an import path element)ui--kitui-kitIt also compared bytes rather than runes around multi-byte letters. These strings end up in every generated id (
ID,IDTarget, and the htmx selectors' name matching), so a page field or component method named with an underscore got an id containing a control character.Fix
unicode.ToLower, and find word starts withunicode.IsUpper/IsLower.--that jackielii/structpages#41 uses as the keyed-id separator.Compatibility
pageÜber). A function's package path element also changes if it has leading, trailing or doubled hyphens, or a hyphen before a capital.RowEditandRow_Edit) are reported by Mount's existing id uniqueness check. There's a test for it.Testing
case_folding_test.go:Row_Editid selected byHTMXRenderTarget;Interaction with #41
Rebased onto main after jackielii/structpages#41 merged. #41's
idSegment, which collapsed hyphen runs aftercamelToKebab, is now the same ascamelToKebab, so this PR removes it. Its test cases moved tocase_folding_test.go.