Skip to content
This repository has been archived by the owner on May 20, 2019. It is now read-only.

Commit

Permalink
Fix path open/closed byte parity (elixir-ecto#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantswain authored and José Valim committed Jan 25, 2018
1 parent 999f119 commit 7edd2b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/postgrex/extensions/path.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ defmodule Postgrex.Extensions.Path do
end

def decode_path(<<o::int8, n::int32, point_data::binary-size(n)-unit(128)>>) do
open = (o == 1)
open = (o == 0)
points = decode_points(point_data, [])
%Postgrex.Path{open: open, points: points}
end

def open_to_byte(true), do: 1
def open_to_byte(false), do: 0
def open_to_byte(true), do: 0
def open_to_byte(false), do: 1

defp decode_points(<<>>, points), do: Enum.reverse(points)
defp decode_points(<<x::float64, y::float64, rest::bits>>, points) do
Expand Down
3 changes: 2 additions & 1 deletion test/query_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ defmodule QueryTest do
p1 = %Postgrex.Point{x: 0.0, y: 0.0}
p2 = %Postgrex.Point{x: 1.0, y: 3.0}
p3 = %Postgrex.Point{x: -4.0, y: 3.14}
path = %Postgrex.Path{points: [p1, p2, p3], open: false}
path = %Postgrex.Path{points: [p1, p2, p3], open: true}
assert [[path]] == query("SELECT '[(0.0,0.0),(1.0,3.0),(-4.0,3.14)]'::path", [])
assert [[%{path | open: false}]] == query("SELECT '((0.0,0.0),(1.0,3.0),(-4.0,3.14))'::path", [])
assert %ArgumentError{} = catch_error(query("SELECT $1::path", [1.0]))
bad_path = %Postgrex.Path{points: "foo", open: false}
assert %ArgumentError{} = catch_error(query("SELECT $1::path", [bad_path]))
Expand Down

0 comments on commit 7edd2b2

Please sign in to comment.