Skip to content
Open
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
7 changes: 7 additions & 0 deletions .changeset/olive-llamas-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@core/elixir-client': patch
---

Fix `Electric.Client.EctoAdapter.ArrayDecoder` decoding of escaped backslashes in
quoted PostgreSQL array elements: `\\` now decodes to a single backslash, matching
PostgreSQL semantics and the TypeScript client's parser.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ if Code.ensure_loaded?(Ecto) do
defp decode_quoted_elem(<<?", rest::bitstring>>, acc, state),
do: {rest, cast_quoted(acc, state)}

defp decode_quoted_elem(<<"\\\"", rest::bitstring>>, acc, state),
do: decode_quoted_elem(rest, [acc | [?"]], state)
defp decode_quoted_elem(<<?\\, c::utf8, rest::bitstring>>, acc, state),
do: decode_quoted_elem(rest, [acc | <<c::utf8>>], state)

defp decode_quoted_elem(<<c::utf8, rest::bitstring>>, acc, state),
do: decode_quoted_elem(rest, [acc | <<c::utf8>>], state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ defmodule Electric.Client.EctoAdapter.ArrayDecoderTest do
"c"
]

assert ArrayDecoder.decode!(~S[{"a\\b"}], :string) == ["a\\b"]
assert ArrayDecoder.decode!(~S[{"a\\\\b"}], :string) == ["a\\\\b"]

assert ArrayDecoder.decode!(~S[{NULL,NULL,"NULL"}], :string) == [nil, nil, "NULL"]
end

Expand Down