Skip to content

Commit

Permalink
Alwaus validate comment
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Oct 24, 2024
1 parent 4971a27 commit d96e41a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/postgrex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ defmodule Postgrex do
@spec query(conn, iodata, list, [execute_option]) ::
{:ok, Postgrex.Result.t()} | {:error, Exception.t()}
def query(conn, statement, params, opts \\ []) do
:ok = validate_comment(opts)
validate_comment!(opts)

if name = Keyword.get(opts, :cache_statement) do
query = %Query{name: name, cache: :statement, statement: IO.iodata_to_binary(statement)}
Expand Down Expand Up @@ -330,16 +330,16 @@ defmodule Postgrex do
end
end

defp validate_comment(opts) do
defp validate_comment!(opts) do
case Keyword.get(opts, :comment) do
nil ->
:ok
false

comment when is_binary(comment) ->
if String.contains?(comment, "*/") do
raise @comment_validation_error
else
:ok
true
end
end
end
Expand Down Expand Up @@ -388,8 +388,7 @@ defmodule Postgrex do
{:ok, Postgrex.Query.t()} | {:error, Exception.t()}
def prepare(conn, name, statement, opts \\ []) do
query = %Query{name: name, statement: statement}
prepare? = Keyword.get(opts, :comment) == nil
opts = Keyword.put(opts, :postgrex_prepare, prepare?)
opts = Keyword.put(opts, :postgrex_prepare, not validate_comment!(opts))
DBConnection.prepare(conn, query, opts)
end

Expand All @@ -399,8 +398,7 @@ defmodule Postgrex do
"""
@spec prepare!(conn, iodata, iodata, [option]) :: Postgrex.Query.t()
def prepare!(conn, name, statement, opts \\ []) do
prepare? = Keyword.get(opts, :comment) == nil
opts = Keyword.put(opts, :postgrex_prepare, prepare?)
opts = Keyword.put(opts, :postgrex_prepare, not validate_comment!(opts))
DBConnection.prepare!(conn, %Query{name: name, statement: statement}, opts)
end

Expand Down

0 comments on commit d96e41a

Please sign in to comment.