fix: escape database values in generated Swift string literals - #1132
Closed
Kjubikstronk wants to merge 1 commit into
Closed
fix: escape database values in generated Swift string literals#1132Kjubikstronk wants to merge 1 commit into
Kjubikstronk wants to merge 1 commit into
Conversation
Kjubikstronk
requested review from
a team,
avallete and
soedirgo
as code owners
August 31, 2026 08:10
Contributor
|
Thank you for the contribution! postgres-meta's type generation is moving to the shared |
Author
|
Good, sdk#123 is the right home for it. Closing this one. One thing in case it is useful over there: in this template both the enum cases and the CodingKeys come out of the same |
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.
Closes #1126.
generateEnuminterpolates database values straight into a quoted Swift literal:An enum label or column name containing a double quote closes the literal early, and
swiftc -parsethen rejects the file as an unterminated string literal. Backslashes and control characters cause the same class of problem.This escapes the value before interpolating: backslash and double quote get their Swift escapes, tab, newline and carriage return use the short forms, and any remaining control character becomes
u{n}. Swift unescapes these at compile time, so the raw enum label and coding key still round-trip to the original database value. Values with none of these characters are emitted exactly as before.That one function generates both the enum cases and the CodingKeys, so both paths mentioned in the issue are covered by the single change.
Added
test/server/templates/swift.test.ts, a pure unit test file needing no database, in the same style as the existinggo.test.ts. It covers a quote in an enum label, a quote in a column name, a backslash, and an ordinary name. The first three fail without the change and the last passes either way, so the existing output is pinned too.prettier --checkandtsc -p tsconfig.json --noEmitare clean.