Skip to content

fix: parse named params by rune; support :name::type casts#996

Open
sonnemusk wants to merge 1 commit into
jmoiron:masterfrom
sonnemusk:fix/named-unicode-and-pg-cast
Open

fix: parse named params by rune; support :name::type casts#996
sonnemusk wants to merge 1 commit into
jmoiron:masterfrom
sonnemusk:fix/named-unicode-and-pg-cast

Conversation

@sonnemusk

Copy link
Copy Markdown

Summary

compileNamedQuery had two related bugs called out in-tree (FIXME + commented failing test) and in #983:

  1. Unicode names — walking the query by byte made multi-byte letters unusable as bind names (:あ, :名前).
  2. PostgreSQL casts:id::int hit unexpected ':' while reading named param because the first cast colon was treated as a new name start.

Changes

  • Parse named parameters rune-wise via utf8.DecodeRune
  • When a completed name is followed by ::, end the bind and emit the cast literally
  • Re-enable the unicode test case and add a :id::int / :name::text case

Test plan

  • go test -count=1 -run TestCompileQuery .
  • go test -count=1 -short .

compileNamedQuery previously walked the query byte-wise, so multi-byte
Unicode parameter names (e.g. :名前) were broken, and a PostgreSQL cast
immediately after a named parameter (:id::int) failed with an unexpected
colon error.

Parse names with utf8.DecodeRune, and treat '::' after a completed name
as a literal cast rather than a new bind.
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.

1 participant