-
Notifications
You must be signed in to change notification settings - Fork 293
allow to append comment to query #709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
be74cce
409d07d
a5121fb
78a8069
7f2f5db
518ee8f
70fd3e3
f783aa5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,6 +16,9 @@ defmodule Postgrex.Protocol do | |||||
message: | ||||||
"`:commit_comment` option cannot contain sequence \"*/\"" | ||||||
) | ||||||
@comment_validation_error Postgrex.Error.exception( | ||||||
message: "`:comment` option cannot contain sequence \"*/\"" | ||||||
) | ||||||
|
||||||
defstruct sock: nil, | ||||||
connection_id: nil, | ||||||
|
@@ -347,8 +350,17 @@ defmodule Postgrex.Protocol do | |||||
status = new_status(opts, prepare: prepare) | ||||||
|
||||||
case prepare do | ||||||
true -> parse_describe_close(s, status, query) | ||||||
false -> parse_describe_flush(s, status, query) | ||||||
true -> | ||||||
parse_describe_close(s, status, query) | ||||||
|
||||||
false -> | ||||||
comment = Keyword.get(opts, :comment) | ||||||
|
||||||
if is_binary(comment) && String.contains?(comment, "*/") do | ||||||
|
if is_binary(comment) && String.contains?(comment, "*/") do | |
if is_binary(comment) and String.contains?(comment, "*/") do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this validation to the client. There is no need to crash the connection on bad argument. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So should I just remove the whole if
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should move it to the client, to the Postgrex
module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it there in the query function.
In theory the comment could be also an iolist but Currently we are getting CaseClauseError.
I think this is hard to validate for sql injection unless we first dump it to a string.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we may no longer go wit hthis PR, but I wonder if this could be dealt as IO lists:
statement = query.statement <> "/*#{comment}*/" | |
statement = [query.statement, "/*", comment, "*/"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1851,6 +1851,15 @@ defmodule QueryTest do | |
assert [["1", "2"], ["3", "4"]] = query("COPY (VALUES (1, 2), (3, 4)) TO STDOUT", [], opts) | ||
end | ||
|
||
test "comment", context do | ||
assert [[123]] = query("select 123", [], comment: "query comment goes here") | ||
|
||
assert_raise Postgrex.Error, fn -> | ||
query("select 123", [], comment: "*/ DROP TABLE 123 --") | ||
end | ||
end | ||
|
||
@tag :big_binary | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes problems when I log all queries in postgres - this inserts all the data in the log file, I need to have a way to skip it. |
||
test "receive packet with remainder greater than 64MB", context do | ||
# to ensure remainder is more than 64MB use 64MBx2+1 | ||
big_binary = :binary.copy(<<1>>, 128 * 1024 * 1024 + 1) | ||
|
Uh oh!
There was an error while loading. Please reload this page.