Skip to content

Keep a trailing underscore in toCamel and toPascal - #1313

Merged
porsager merged 1 commit into
porsager:masterfrom
efeesrefinal:fix/camel-trailing-underscore
Nov 11, 2026
Merged

porsager merged 1 commit into
porsager:masterfrom
efeesrefinal:fix/camel-trailing-underscore

Conversation

@efeesrefinal

Copy link
Copy Markdown
Contributor

With transform: postgres.camel, a jsonb key that ends with _ makes the whole query throw:

await sql`select '{"a_":1}'::jsonb as x`
// TypeError: Cannot read properties of undefined (reading 'toUpperCase')

toCamel and toPascal read x[++i] after the last _. An empty key also became "undefined" with toCamel and threw with toPascal.

Now a trailing _ is kept (a_ stays a_, b_c_ becomes bC_), so fromCamel gives the same name back. #1009 fixed the same crash but dropped the underscore, and it was closed without a merge.

Tested against PostgreSQL 16:

  • The new unit test and the new test in tests/transform.js fail on master and pass with the change.
  • node tests/unit, the 25 tests in tests/transform.js and tests/simulate.js (2000 seeds) pass. eslint@8 --max-warnings 0 src tests is clean.
  • I did not get a clean full integration run in my container (SSL, unix socket and prepared transaction tests need a setup I don't have), so those are not checked.

A name ending with _ made x[++i] undefined, so a jsonb key like "a_" threw a
TypeError with postgres.camel and the whole query failed. An empty key became
"undefined" with toCamel and threw with toPascal.
@porsager

Copy link
Copy Markdown
Owner

Huh, that's a sneaky one :) Good find

@porsager
porsager merged commit 5b4b90c into porsager:master Nov 11, 2026
37 checks passed
porsager added a commit that referenced this pull request Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants