Fix toSnakeCase/toCamelCase silently dropping non-Latin identifiers - #6144
Open
nexrall wants to merge 1 commit into
Open
Fix toSnakeCase/toCamelCase silently dropping non-Latin identifiers#6144nexrall wants to merge 1 commit into
nexrall wants to merge 1 commit into
Conversation
The word-splitting regex in toSnakeCase/toCamelCase only matched ASCII
letters and digits ([\da-z], [A-Z]). Array.prototype.match() silently
discards any character that doesn't match one of the pattern's
alternatives, so Korean, Japanese, Cyrillic, and other non-Latin
characters were dropped entirely rather than left unchanged - not
merely miscased.
For snakeCase.table() this means a Korean column name like 칼럼명
becomes an empty string, which drizzle-kit generate turns into an
invalid empty SQL identifier (`` `` ``), and the resulting migration
fails to apply.
Fix: generalize the word-boundary regex with Unicode property escapes
(\p{Ll}, \p{Lu}, \p{Lo}) instead of ASCII character classes:
- \p{Ll}/\p{Lu} extend the existing lower/upper-case logic to any
script with case distinctions (Latin, Cyrillic, Greek, etc.), so
accented Latin (café, Résumé) is preserved instead of stripped.
- \p{Lo} is added for caseless scripts (CJK ideographs, Hangul
syllables) that have no upper/lower distinction to split words on.
All existing ASCII test cases keep producing identical output.
Verified end-to-end (not just the unit-level regex) by building the
package and running the exact schema from the issue through
snakeCase.table() -> getTableConfig(): the Korean column resolves to
'칼럼명' instead of ''.
Fixes drizzle-team#6082
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.
Summary
toSnakeCase/toCamelCase's word-splitting regex only matched ASCII letters and digits ([\da-z],[A-Z]).String.prototype.match()silently discards any character that doesn't match one of the pattern's alternatives, so Korean, Japanese, Cyrillic, and other non-Latin characters were dropped entirely rather than left unchanged — not merely miscased.For
snakeCase.table()this means a Korean column name like칼럼명becomes an empty string, whichdrizzle-kit generateturns into an invalid empty SQL identifier (``), and the resulting migration fails to apply.Closes #6082
Root cause
None of the three alternatives matches a Hangul syllable, CJK ideograph, or even accented Latin (
é,ñ) — so.match()simply omits those characters from the result array instead of keeping them as their own word.Fix
Generalized the word-boundary regex with Unicode property escapes instead of ASCII character classes:
\p{Ll}/\p{Lu}extend the existing lower/upper-case logic to any script with case distinctions (Latin, Cyrillic, Greek, etc.), so accented Latin (café,Résumé) is preserved instead of stripped.\p{Lo}is a new alternative for caseless scripts (CJK ideographs, Hangul syllables) that have no upper/lower distinction to split words on.All existing ASCII test cases keep producing byte-identical output — this only changes behavior for input that was previously being silently corrupted.
칼럼명''(bug)칼럼명日本語Testtest(bug, dropped 日本語)日本語_testcafécaf(bug, dropped é)cafédrizzleORMdrizzle_ormdrizzle_orm(unchanged)drizzleOrmAndKitdrizzle_orm_and_kitdrizzle_orm_and_kit(unchanged)Test plan
tests/casing/casing.test.tscovering the exact Korean case from the issue, a mixed Japanese/Latin case, and an accented-Latin non-regression case.pnpm vitest run tests/casing/casing.test.ts— 9/9 passing.pnpm vitest run tests/(drizzle-orm package) — 967/970 passing. The 3 failures are intests/sql-builder.test.tsand are pre-existing on unmodifiedbetaHEAD — verified by stashing this fix entirely and re-running, which reproduces the same 3 failures unrelated tocasing.ts.tsc --noEmit— no new errors. The one pre-existing error (types-bench.ts, missing a generated scaffold file) reproduces identically on unmodifiedbetaHEAD.snakeCase.table()pipeline (not just the unit-level regex): built the package locally and ran the exact schema from the issue throughsnakeCase.table()→getTableConfig(). Before the fix, the Korean column resolves to''(bug reproduced exactly as reported); after the fix, it resolves to칼럼명, matching the output of an unaffectedsqliteTable()call with the same column name.Why this targets
betaThe issue's repro uses
snakeCase.table(), which only exists on the1.0.0-rcline (beta) — it isn't present onmain(0.45.x). The underlyingtoSnakeCase/toCamelCaseregex bug is present on both branches, but onlybetacan run the exact reproduction from the issue.