Skip to content

Commit 18cfd26

Browse files
Skip empty and commented pgpass entries
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
1 parent 405474b commit 18cfd26

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

sqlx-core/src/postgres/options/pgpass.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,17 @@ fn load_password_from_line(
8989
database: Option<&str>,
9090
) -> Option<String> {
9191
let whole_line = line;
92-
matches_next_field(whole_line, &mut line, host)?;
93-
matches_next_field(whole_line, &mut line, &port.to_string())?;
94-
matches_next_field(whole_line, &mut line, username)?;
95-
matches_next_field(whole_line, &mut line, database.unwrap_or_default())?;
96-
Some(line.to_owned())
92+
93+
match line.trim_start().chars().next() {
94+
None | Some('#') => None,
95+
_ => {
96+
matches_next_field(whole_line, &mut line, host)?;
97+
matches_next_field(whole_line, &mut line, &port.to_string())?;
98+
matches_next_field(whole_line, &mut line, username)?;
99+
matches_next_field(whole_line, &mut line, database.unwrap_or_default())?;
100+
Some(line.to_owned())
101+
}
102+
}
97103
}
98104

99105
/// check if the next field matches the provided value

0 commit comments

Comments
 (0)