FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(golang): escape generated enum values (fix #4448) by sjh9714 · Pull Request #4449 · sqlc-dev/sqlc · GitHub

/ sqlc Public

fix(golang): escape generated enum values (fix #4448) - #4449

Open
sjh9714 wants to merge 1 commit into
sqlc-dev:mainfrom
sjh9714:fix-go-enum-value-escaping
Open

fix(golang): escape generated enum values (fix #4448)#4449
sjh9714 wants to merge 1 commit into
sqlc-dev:mainfrom
sjh9714:fix-go-enum-value-escaping

Conversation

sjh9714 commented May 20, 2026

Copy link
Copy Markdown

Summary

Fixes PostgreSQL enum values containing Go string metacharacters being emitted into generated Go constants without string literal escaping.

What changed

  • Updated the Go enum constant template to render enum values with Go string literal escaping (printf "%q").
  • Added an end-to-end PostgreSQL stdlib fixture covering a backslash-n enum value and a double-quote/code-like enum value.

Why

The previous template wrapped raw enum values in quotes, so user\nadmin became a newline at runtime and values containing " could produce invalid generated Go code. The new template delegates literal formatting to Go's %q formatting.

Testing

  • Red check: go test ./internal/endtoend -run 'TestReplay/base/enum_escaped_values/postgresql/stdlib' failed before the template change with a generated models.go diff missing escapes.
  • go test ./internal/endtoend -run 'TestReplay/base/enum_escaped_values/postgresql/stdlib'
  • go test ./internal/codegen/golang
  • gofmt -l internal/endtoend/testdata/enum_escaped_values/postgresql/stdlib/go/db.go internal/endtoend/testdata/enum_escaped_values/postgresql/stdlib/go/models.go internal/endtoend/testdata/enum_escaped_values/postgresql/stdlib/go/query.sql.go
  • go test ./...
  • go test --tags=examples -timeout 20m ./...

Fixes #4448

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Silent Data Corruption via Unescaped Enum Values in Generated Go Code

1 participant


Back | FazBrowse Home | New Git URL