From 7edd2b2ce2940da4ce4164355310c06c6dd5ae07 Mon Sep 17 00:00:00 2001 From: Dan Swain Date: Sat, 28 Oct 2017 07:09:05 -0400 Subject: [PATCH] Fix path open/closed byte parity (#342) Fixes #341 --- lib/postgrex/extensions/path.ex | 6 +++--- test/query_test.exs | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/postgrex/extensions/path.ex b/lib/postgrex/extensions/path.ex index d3a1b80a7..d29b234dc 100644 --- a/lib/postgrex/extensions/path.ex +++ b/lib/postgrex/extensions/path.ex @@ -29,13 +29,13 @@ defmodule Postgrex.Extensions.Path do end def decode_path(<>) 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(<>, points) do diff --git a/test/query_test.exs b/test/query_test.exs index de31accf2..bd338601f 100644 --- a/test/query_test.exs +++ b/test/query_test.exs @@ -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]))