diff --git a/reflex/utils/format.py b/reflex/utils/format.py index 857a61f82..7d18460b5 100644 --- a/reflex/utils/format.py +++ b/reflex/utils/format.py @@ -122,7 +122,7 @@ def to_snake_case(text: str) -> str: The snake case string. """ s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", text) - return re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower() + return re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower().replace("-", "_") def to_camel_case(text: str) -> str: diff --git a/tests/utils/test_format.py b/tests/utils/test_format.py index 768cc353a..8e6699962 100644 --- a/tests/utils/test_format.py +++ b/tests/utils/test_format.py @@ -117,6 +117,8 @@ def test_indent(text: str, indent_level: int, expected: str, windows_platform: b ("camelTwoHumps", "camel_two_humps"), ("_start_with_underscore", "_start_with_underscore"), ("__start_with_double_underscore", "__start_with_double_underscore"), + ("kebab-case", "kebab_case"), + ("double-kebab-case", "double_kebab_case"), ], ) def test_to_snake_case(input: str, output: str):