Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previous behavior
When parsing
pgpass
files, the BufReader'sread_line
function is used which does not strip \n or \r. To handle this, a substring was created that strips out the last character (&line[..line.len() - 1]
)Why is this an issue
This behavior fails in two cases:
Case (2) is subtle because it means if you modify your pgpass to add a new entry and forget to add a trailing newline to your file,
[..line.len() - 1]
will cut off the last letter of your password (ex:hunter12
->hunter1
) giving you an authentication error.How can we fix it?
Two options:
read_line
to thelines
method which strips the newline characters for you (I don't think this is a performance concern because pgpass files are presumably not large files)Tests
I noticed there weren't any tests for
load_password_from_file
-- only forload_password_from_line
. I assume it's because setup for a test on file reading is tedious and any issue would get caught integration tests. However, this means I'm not sure what you suggest for a test for this specific case. Please let me know if you're okay without a test or if you have a specific way you'd like me to set it up (or push to my branch yourself)