From 3892e45c07ddc6f41204d86a0f894ba719b16ace Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Tue, 6 Jul 2021 16:04:51 -0400 Subject: [PATCH] Mark code that uses improper lists as generated (#556) Addresses [#549](https://github.com/elixir-ecto/postgrex/issues/549) by marking code that creates improper lists as `generated: true`. --- lib/postgrex/extensions/bit_string.ex | 2 +- lib/postgrex/extensions/box.ex | 2 +- lib/postgrex/extensions/line_segment.ex | 2 +- lib/postgrex/extensions/name.ex | 2 +- lib/postgrex/extensions/numeric.ex | 2 +- lib/postgrex/extensions/path.ex | 2 +- lib/postgrex/extensions/polygon.ex | 2 +- lib/postgrex/extensions/raw.ex | 2 +- lib/postgrex/extensions/uuid.ex | 2 +- lib/postgrex/type_module.ex | 4 ++-- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/postgrex/extensions/bit_string.ex b/lib/postgrex/extensions/bit_string.ex index bf06629a1..cbe990bbb 100644 --- a/lib/postgrex/extensions/bit_string.ex +++ b/lib/postgrex/extensions/bit_string.ex @@ -6,7 +6,7 @@ defmodule Postgrex.Extensions.BitString do def init(opts), do: Keyword.fetch!(opts, :decode_binary) def encode(_) do - quote location: :keep do + quote location: :keep, generated: true do val when is_binary(val) -> [<> | val] diff --git a/lib/postgrex/extensions/box.ex b/lib/postgrex/extensions/box.ex index 64e436223..15a2f8a7b 100644 --- a/lib/postgrex/extensions/box.ex +++ b/lib/postgrex/extensions/box.ex @@ -5,7 +5,7 @@ defmodule Postgrex.Extensions.Box do alias Postgrex.Extensions.Point def encode(_) do - quote location: :keep do + quote location: :keep, generated: true do %Postgrex.Box{upper_right: p1, bottom_left: p2} -> encoded_p1 = Point.encode_point(p1, Postgrex.Box) encoded_p2 = Point.encode_point(p2, Postgrex.Box) diff --git a/lib/postgrex/extensions/line_segment.ex b/lib/postgrex/extensions/line_segment.ex index 9b057705b..5534b5d34 100644 --- a/lib/postgrex/extensions/line_segment.ex +++ b/lib/postgrex/extensions/line_segment.ex @@ -5,7 +5,7 @@ defmodule Postgrex.Extensions.LineSegment do alias Postgrex.Extensions.Point def encode(_) do - quote location: :keep do + quote location: :keep, generated: true do %Postgrex.LineSegment{point1: p1, point2: p2} -> encoded_p1 = Point.encode_point(p1, Postgrex.LineSegment) encoded_p2 = Point.encode_point(p2, Postgrex.LineSegment) diff --git a/lib/postgrex/extensions/name.ex b/lib/postgrex/extensions/name.ex index 5b73c6b3e..7bce9bf99 100644 --- a/lib/postgrex/extensions/name.ex +++ b/lib/postgrex/extensions/name.ex @@ -6,7 +6,7 @@ defmodule Postgrex.Extensions.Name do def init(opts), do: Keyword.fetch!(opts, :decode_binary) def encode(_) do - quote location: :keep do + quote location: :keep, generated: true do name when is_binary(name) and byte_size(name) < 64 -> [<> | name] diff --git a/lib/postgrex/extensions/numeric.ex b/lib/postgrex/extensions/numeric.ex index dec69f7d3..f0036a3e9 100644 --- a/lib/postgrex/extensions/numeric.ex +++ b/lib/postgrex/extensions/numeric.ex @@ -4,7 +4,7 @@ defmodule Postgrex.Extensions.Numeric do use Postgrex.BinaryExtension, send: "numeric_send" def encode(_) do - quote location: :keep do + quote location: :keep, generated: true do %Decimal{} = decimal -> data = unquote(__MODULE__).encode_numeric(decimal) [<> | data] diff --git a/lib/postgrex/extensions/path.ex b/lib/postgrex/extensions/path.ex index 81e715581..1f95920df 100644 --- a/lib/postgrex/extensions/path.ex +++ b/lib/postgrex/extensions/path.ex @@ -6,7 +6,7 @@ defmodule Postgrex.Extensions.Path do alias Postgrex.Extensions.Point def encode(_) do - quote location: :keep do + quote location: :keep, generated: true do %Postgrex.Path{open: o, points: ps} when is_list(ps) and is_boolean(o) -> open_byte = Path.open_to_byte(o) len = length(ps) diff --git a/lib/postgrex/extensions/polygon.ex b/lib/postgrex/extensions/polygon.ex index 1a2403576..c6495688c 100644 --- a/lib/postgrex/extensions/polygon.ex +++ b/lib/postgrex/extensions/polygon.ex @@ -6,7 +6,7 @@ defmodule Postgrex.Extensions.Polygon do alias Postgrex.Extensions.Point def encode(_) do - quote location: :keep do + quote location: :keep, generated: true do %Postgrex.Polygon{vertices: vertices} when is_list(vertices) -> len = length(vertices) diff --git a/lib/postgrex/extensions/raw.ex b/lib/postgrex/extensions/raw.ex index a0c30a299..72ce13957 100644 --- a/lib/postgrex/extensions/raw.ex +++ b/lib/postgrex/extensions/raw.ex @@ -15,7 +15,7 @@ defmodule Postgrex.Extensions.Raw do def init(opts), do: Keyword.fetch!(opts, :decode_binary) def encode(_) do - quote location: :keep do + quote location: :keep, generated: true do bin when is_binary(bin) -> [<> | bin] diff --git a/lib/postgrex/extensions/uuid.ex b/lib/postgrex/extensions/uuid.ex index 59fef036c..1d34e6a28 100644 --- a/lib/postgrex/extensions/uuid.ex +++ b/lib/postgrex/extensions/uuid.ex @@ -6,7 +6,7 @@ defmodule Postgrex.Extensions.UUID do def init(opts), do: Keyword.fetch!(opts, :decode_binary) def encode(_) do - quote location: :keep do + quote location: :keep, generated: true do uuid when is_binary(uuid) and byte_size(uuid) == 16 -> [<<16::int32>> | uuid] diff --git a/lib/postgrex/type_module.ex b/lib/postgrex/type_module.ex index 6261bc3be..23e7470f9 100644 --- a/lib/postgrex/type_module.ex +++ b/lib/postgrex/type_module.ex @@ -333,7 +333,7 @@ defmodule Postgrex.TypeModule do end defp decode_rows(dispatch, rest, acc, rem, full, rows) do - quote location: :keep do + quote location: :keep, generated: true do def decode_rows(binary, types, rows) do decode_rows(binary, byte_size(binary), types, rows) end @@ -464,7 +464,7 @@ defmodule Postgrex.TypeModule do decode_tuple_dispatch(extension, format, rest, oids, n, acc) end - quote do + quote generated: true do def decode_tuple(<>, count, types) when is_integer(count) do decode_tuple(rest, count, types, 0, []) end