Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Array(Bytes) encoding for query params containing non-Unicode text #290

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spec/pq/param_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe PQ::Param do
it_encodes_array([1, 2, 3], "{1,2,3}")
it_encodes_array([1.2, 3.4, 5.6], "{1.2,3.4,5.6}")
it_encodes_array([%(a), %(\\b~), %(c\\"d), %(\uFF8F)], %({"a","\\\\b~","c\\\\\\"d","\uFF8F"}))
it_encodes_array([%(this is a "slice").to_slice], %({"\\\\x7468697320697320612022736c69636522"}))
it_encodes_array(["baz, bar"], %({"baz, bar"}))
it_encodes_array(["foo}"], %({"foo}"}))
it_encodes_array([nil, nil], %({NULL,NULL}))
Expand Down
6 changes: 4 additions & 2 deletions src/pq/param.cr
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ module PQ
end

def self.encode_array(io, value : Bytes)
io << '"'
io << String.new(value).gsub(%("), %(\\"))
io << %{"\\\\x}
value.each do |byte|
byte.to_s io, base: 16, precision: 2
end
io << '"'
end

Expand Down
Loading