diff --git a/spec/pq/param_spec.cr b/spec/pq/param_spec.cr index 39cdd4f9..54831247 100644 --- a/spec/pq/param_spec.cr +++ b/spec/pq/param_spec.cr @@ -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})) diff --git a/src/pq/param.cr b/src/pq/param.cr index 757a4384..5232d817 100644 --- a/src/pq/param.cr +++ b/src/pq/param.cr @@ -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