Skip to content
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
3 changes: 2 additions & 1 deletion lib/ecto/adapters/myxql/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1626,8 +1626,9 @@ if Code.ensure_loaded?(MyXQL) do

defp escape_json_key(value) when is_binary(value) do
value
|> :binary.replace("\\", "\\\\", [:global])
|> :binary.replace("\"", "\\\"", [:global])
|> escape_string()
|> :binary.replace("\"", "\\\\\"", [:global])
end

defp ecto_cast_to_db(:id, _query), do: "unsigned"
Expand Down
6 changes: 6 additions & 0 deletions test/ecto/adapters/myxql_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,12 @@ defmodule Ecto.Adapters.MyXQLTest do

query = Schema |> select([s], json_extract_path(s.meta, ["\"a"])) |> plan()
assert all(query) == ~s{SELECT json_extract(s0.`meta`, '$."\\\\"a"') FROM `schema` AS s0}

query = Schema |> select([s], json_extract_path(s.meta, ["a\\b"])) |> plan()
assert all(query) == ~S{SELECT json_extract(s0.`meta`, '$."a\\\\b"') FROM `schema` AS s0}

query = Schema |> select([s], json_extract_path(s.meta, ["a\\"])) |> plan()
assert all(query) == ~S{SELECT json_extract(s0.`meta`, '$."a\\\\"') FROM `schema` AS s0}
end

test "nested expressions" do
Expand Down
Loading