Skip to content

Commit 3c0fe1c

Browse files
committed
Remove unsafe interpolation in PostgreSQL
1 parent 8450566 commit 3c0fe1c

2 files changed

Lines changed: 1 addition & 23 deletions

File tree

lib/ecto/adapters/postgres/connection.ex

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -494,18 +494,7 @@ if Code.ensure_loaded?(Postgrex) do
494494

495495
defp from(%{from: %{source: source, hints: hints}} = query, sources) do
496496
{from, name} = get_source(query, sources, 0, source)
497-
[" FROM ", from, " AS ", name | hints(hints)]
498-
end
499-
500-
defp hints([]), do: []
501-
defp hints(hint) when is_binary(hint), do: [?\s | hint]
502-
503-
defp hints([{key, value} | tail]) do
504-
[?\s, to_string(key), ?\s, to_string(value) | hints(tail)]
505-
end
506-
507-
defp hints([hint | tail]) do
508-
[?\s, hint | hints(tail)]
497+
[" FROM ", from, " AS ", name | Enum.map(hints, &[?\s | &1])]
509498
end
510499

511500
defp cte(%{with_ctes: %WithExpr{queries: [_ | _]}} = query, sources) do

test/ecto/adapters/postgres_test.exs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,6 @@ defmodule Ecto.Adapters.PostgresTest do
9494
assert all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 TABLESAMPLE system_rows(1)}
9595
end
9696

97-
test "from with hints list of tuples" do
98-
one = 1
99-
query =
100-
Schema
101-
|> from(hints: ["TABLESAMPLE SYSTEM": one])
102-
|> select([r], r.x)
103-
|> plan()
104-
105-
assert all(query) == ~s{SELECT s0."x" FROM "schema" AS s0 TABLESAMPLE SYSTEM 1}
106-
end
107-
10897
test "from without schema" do
10998
query = "posts" |> select([r], r.x) |> plan()
11099
assert all(query) == ~s{SELECT p0."x" FROM "posts" AS p0}

0 commit comments

Comments
 (0)