Repository navigation
fix: escape backticks in generated Go struct tags - #1131
Kjubikstronk wants to merge 1 commit into
Conversation
|
Thank you for the contribution! postgres-meta's type generation is moving to the shared |
|
Makes sense, and sdk#122 is the better fix, since escaping quotes, backslashes and control characters means |
… names Go struct tags were interpolated into raw string literals verbatim, so a column name containing a backtick terminated the literal early and the generated source failed to parse. Names containing double quotes or backslashes compiled but produced tags that reflect.StructTag could not round-trip. Column and composite attribute names are now quoted with JSON.stringify, whose escape sequences are a subset of Go's, so reflect.StructTag.Get recovers the exact name. Ordinary names keep their previous raw literal representation; only names containing a backtick fall back to an interpreted literal, since Go raw literals cannot contain one. Validated against the Go toolchain: generated structs for names with backticks, quotes, backslashes and control characters parse under gofmt and round-trip through reflect.StructTag.Get. Ported from supabase/postgres-meta#1127 and supabase/postgres-meta#1131.
|
Thanks for explaining the move, and for re-landing it rather than just closing it. Your version in supabase/sdk#122 is the better fix: escaping quotes, backslashes and control characters as well means One small ask. supabase/sdk#122 links #1125, the issue, but not this PR, so there is no trail from the merged fix back to where the change came from. Would you mind adding a line to the description pointing at it? A "supersedes #1131" would do it. Not a complaint about the close, that was clearly the right call once the templates are going away. It just makes the work findable. |
Closes #1125.
The Go generator writes struct tags as a raw string literal, ```go
json:"NAME"