fix(postgrest-typegen): escape database values in Swift string literals - #123
Merged
Conversation
The Swift generator interpolated database-provided enum labels and column names directly into string literals for enum raw values and CodingKeys. A double quote terminated the literal early, a backslash could start an escape or interpolation sequence, and line breaks or control characters are invalid in single-line literals, so such names produced Swift that failed to compile. Escape those characters per Swift's string literal grammar; Swift unescapes at compile time, so raw values round-trip unchanged. Identifier positions were already safe because name formatting strips non-alphanumeric characters. Ported from supabase/postgres-meta#1128 and supabase/postgres-meta#1132.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Aug 31, 2026
Tr00d
approved these changes
Aug 31, 2026
grdsdev
approved these changes
Aug 31, 2026
Closed
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
Ports the Swift string literal escaping fix from postgres-meta's open template PRs into this package (the templates are being deleted in favor of this package in supabase/postgres-meta#1084, so open fixes there are triaged and re-landed here).
Database-provided names were interpolated raw into Swift string literals, so a double quote, backslash (including interpolation sequences like
\(...)), or line break in an enum label or column name produced Swift that does not compile (supabase/postgres-meta#1126). AswiftStringLiteralhelper now escapes per Swift's string literal grammar (backslash, quote, tab, newline, carriage return, remaining C0 controls and DEL as\u{n}, plus U+2028/U+2029) and is applied ingenerateEnum, the single rendering point for both vulnerable positions: Postgres enum raw values andCodingKeysraw values.Triage of origin PRs
swiftc -parse.Identifier positions (enum case names, property names) are already safe through the existing
formatForSwiftTypeName/formatForSwiftPropertyNamesanitization, so escaping is only needed at the literal seam. Pre-existing identifier gaps (all-punctuation names yielding empty case names, leading digits) exist upstream too and need a separate sanitization/dedup design; deliberately out of scope.Validation
\(now), newline, tab, CR, BEL, U+2028) across enum raw values and CodingKeys in Select/Insert/Update, plus a pin that ordinary output stays byte-identical.swiftc -parse.check-types,format-and-lint,knip,build,test(95 pass, parity 4/4) all green; parity golden unchanged.