Skip to content

Commit

Permalink
dk-remove_comment_string_validation
Browse files Browse the repository at this point in the history
  • Loading branch information
dkuku committed Oct 29, 2024
1 parent fb9992e commit fe0e410
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
16 changes: 3 additions & 13 deletions lib/postgrex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ defmodule Postgrex do
@max_rows 500
@timeout 15_000

@comment_validation_error Postgrex.Error.exception(
message: "`:comment` option cannot contain sequence \"*/\""
)

### PUBLIC API ###

@doc """
Expand Down Expand Up @@ -332,15 +328,9 @@ defmodule Postgrex do

defp comment_not_present!(opts) do
case Keyword.get(opts, :comment) do
nil ->
true

comment when is_binary(comment) ->
if String.contains?(comment, "*/") do
raise @comment_validation_error
else
false
end
nil -> true
comment when is_binary(comment) -> false
comment when is_list(comment) -> false
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/postgrex/protocol.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ defmodule Postgrex.Protocol do
end

defp parse_describe_comment_msgs(query, comment, tail) when is_binary(comment) do
statement = [query.statement, "/*", comment, "*/"]
statement = [query.statement, ";/*", comment, "*/"]
query = %{query | statement: statement}
parse_describe_msgs(query, tail)
end
Expand Down
6 changes: 3 additions & 3 deletions test/query_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1853,10 +1853,10 @@ defmodule QueryTest do

test "comment", context do
assert [[123]] = query("select 123", [], comment: "query comment goes here")
assert [[123]] = query("select 123", [], comment: "query comment goes here;")
%Postgrex.Error{postgres: error} = query("select 123", [], comment: "*/ select 456 --")

assert_raise Postgrex.Error, fn ->
query("select 123", [], comment: "*/ DROP TABLE 123 --")
end
assert error.message =~ "cannot insert multiple commands into a prepared statement"
end

@tag :big_binary
Expand Down

0 comments on commit fe0e410

Please sign in to comment.