mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 14:34:19 +00:00
Skip empty and commented pgpass entries (#1216)
While running an application a lot of warnings were printed about my pgpass file, like: Malformed line in pgpass file This was due to the fact that my pgpass file contains whitespace and comments to organize it in a better way. This commit ensures we will ignore empty lines and lines that (barring whitespace) start with a comment. This is in line with how PostgreSQL treats these entries in the pgpass file: - https://www.postgresql.org/docs/current/libpq-pgpass.html - function passwordFromFile in src/interfaces/libpq/fe-connect.c
This commit is contained in:
parent
405474b575
commit
78a94240e6
1 changed files with 11 additions and 5 deletions
|
@ -89,11 +89,17 @@ fn load_password_from_line(
|
|||
database: Option<&str>,
|
||||
) -> Option<String> {
|
||||
let whole_line = line;
|
||||
matches_next_field(whole_line, &mut line, host)?;
|
||||
matches_next_field(whole_line, &mut line, &port.to_string())?;
|
||||
matches_next_field(whole_line, &mut line, username)?;
|
||||
matches_next_field(whole_line, &mut line, database.unwrap_or_default())?;
|
||||
Some(line.to_owned())
|
||||
|
||||
match line.trim_start().chars().next() {
|
||||
None | Some('#') => None,
|
||||
_ => {
|
||||
matches_next_field(whole_line, &mut line, host)?;
|
||||
matches_next_field(whole_line, &mut line, &port.to_string())?;
|
||||
matches_next_field(whole_line, &mut line, username)?;
|
||||
matches_next_field(whole_line, &mut line, database.unwrap_or_default())?;
|
||||
Some(line.to_owned())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// check if the next field matches the provided value
|
||||
|
|
Loading…
Reference in a new issue