Commit d845b95
authored
fix: correct snake_case conversion for consecutive uppercase letters in Python (#3587)
`mangleIdentifier()` in `src/languages/python.ts` incorrectly converted
camelCase identifiers with consecutive uppercase letters. For example,
`enforceSSL` became `enforce_sSL` instead of `enforce_ssl`.
The root cause was a single regex (`/[^A-Z][A-Z]/g`) that only handled
simple camelCase boundaries. It couldn't detect where an uppercase
acronym ends and the next word begins.
Replaced with a two-step regex approach:
- `([a-z0-9])([A-Z])` — lowercase/digit to uppercase boundary
- `([A-Z]+)([A-Z][a-z])` — end of uppercase run before a new word
| Input | Before | After |
|-------|--------|-------|
| `enforceSSL` | `enforce_sSL` | `enforce_ssl` |
| `myVPCId` | `my_vPCId` | `my_vpc_id` |
| `getHTTPSUrl` | `get_hTTPSUrl` | `get_https_url` |
| `parseJSON` | `parse_jSON` | `parse_json` |
Added 12 test cases covering acronyms, digit boundaries, single
uppercase letters, simple camelCase regression guards, leading
underscores, already-snake_case passthrough, and multiple acronyms.
---
By submitting this pull request, I confirm that my contribution is made
under the terms of the [Apache 2.0 license].
[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.01 parent e372215 commit d845b95
File tree
3 files changed
+55
-2
lines changed- src/languages
- test/translations/identifiers
3 files changed
+55
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
842 | 842 | | |
843 | 843 | | |
844 | 844 | | |
845 | | - | |
846 | | - | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
847 | 852 | | |
848 | 853 | | |
849 | 854 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
0 commit comments