Repository: launchbadge/sqlx
File: sqlx-postgres/src/options/parse.rs (Rust)

Code before:
                        options = options.options([(key, &*value)]);
                    }
                }

                _ => tracing::warn!(%key, %value, "ignoring unrecognized connect parameter"),
            }
        }

        let options = options.apply_pgpass();

        Ok(options)
    }

    pub(crate) fn build_url(&self) -> Url {
        let host = match &self.socket {
            Some(socket) => {
                utf8_percent_encode(&*socket.to_string_lossy(), NON_ALPHANUMERIC).to_string()
            }
            None => self.host.to_owned(),
        };

        let mut url = Url::parse(&format!(
            "postgres://{}@{}:{}",
            self.username, host, self.port
        ))
        .unwrap();

        if let Some(password) = &self.password {
            let password = utf8_percent_encode(&password, NON_ALPHANUMERIC).to_string();
            let _ = url.set_password(Some(&password));
        }

        if let Some(database) = &self.database {
            url.set_path(&database);
        }

        let ssl_mode = match self.ssl_mode {
            PgSslMode::Allow => "ALLOW",
            PgSslMode::Disable => "DISABLED",
            PgSslMode::Prefer => "PREFERRED",
            PgSslMode::Require => "REQUIRED",
            PgSslMode::VerifyCa => "VERIFY_CA",
            PgSslMode::VerifyFull => "VERIFY_FULL",
        };
        url.query_pairs_mut().append_pair("ssl-mode", ssl_mode);

        if let Some(ssl_root_cert) = &self.ssl_root_cert {
            url.query_pairs_mut()
                .append_pair("ssl-root-cert", &ssl_root_cert.to_string());
        }


Review comment (bug):
```suggestion
        .expect("BUG: generated un-parseable URL");
```

Code after:
                        options = options.options([(key, &*value)]);
                    }
                }

                _ => tracing::warn!(%key, %value, "ignoring unrecognized connect parameter"),
            }
        }

        let options = options.apply_pgpass();

        Ok(options)
    }

    pub(crate) fn build_url(&self) -> Url {
        let host = match &self.socket {
            Some(socket) => {
                utf8_percent_encode(&*socket.to_string_lossy(), NON_ALPHANUMERIC).to_string()
            }
            None => self.host.to_owned(),
        };

        let mut url = Url::parse(&format!(
            "postgres://{}@{}:{}",
            self.username, host, self.port
        ))
        .expect("BUG: generated un-parseable URL");

        if let Some(password) = &self.password {
            let password = utf8_percent_encode(&password, NON_ALPHANUMERIC).to_string();
            let _ = url.set_password(Some(&password));
        }

        if let Some(database) = &self.database {
            url.set_path(&database);
        }

        let ssl_mode = match self.ssl_mode {
            PgSslMode::Allow => "ALLOW",
            PgSslMode::Disable => "DISABLED",
            PgSslMode::Prefer => "PREFERRED",
            PgSslMode::Require => "REQUIRED",
            PgSslMode::VerifyCa => "VERIFY_CA",
            PgSslMode::VerifyFull => "VERIFY_FULL",
        };
        url.query_pairs_mut().append_pair("ssl-mode", ssl_mode);

        if let Some(ssl_root_cert) = &self.ssl_root_cert {
            url.query_pairs_mut()
                .append_pair("ssl-root-cert", &ssl_root_cert.to_string());
        }