Closed larskanis closed 8 years ago
Original comment by Lars Kanis (Bitbucket: larskanis, GitHub: larskanis).
Ruby strings store their encoding specific to each single string object. On the other hand, the client encoding is per connection. Per default PG::TextEncoder::Array#encode
encodes strings to their binary representation as Encoding::BINARY:
decoder.decode encoder.encode(["ä".encode("ibm850"), "ä".encode("iso-8859-1")]) # => ["\x84", "\xE4"]
Alternatively you can request a specific output encoding (typically the client encoding of the connection) as second argument to #encode
. All input strings will be converted accordingly:
decoder.decode encoder.encode(["ä".encode("ibm850"), "ä".encode("iso-8859-1")], Encoding::UTF_8) # => ["ä", "ä"]
I hope this helps.
Original comment by Ilya Shavrin (Bitbucket: [Ilia Shavrin](https://bitbucket.org/Ilia Shavrin), ).
Thanks for the link. I've missed it somehow.
Original report by Ilya Shavrin (Bitbucket: [Ilia Shavrin](https://bitbucket.org/Ilia Shavrin), ).
Hi,
I've noticed wrong serialization result for UTF-8 string arrays. It could lead to incorrect behavior in other sides.
2.3.1 :009 > PG::TextEncoder::Array.new(name: "text[]", delimiter: ',').encode(["a", "š"] ) => "{a,\xC5\xA1}"