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

Code before:
                        _ => {
                            return Err(Error::Configuration(
                                format!("unknown value {value:?} for `immutable`").into(),
                            ));
                        }
                    },

                    "vfs" => options.vfs = Some(Cow::Owned(value.into_owned())),

                    _ => {
                        return Err(Error::Configuration(
                            format!("unknown query parameter `{key}` while parsing connection URL")
                                .into(),
                        ));
                    }
                }
            }
        }

        Ok(options)
    }

    pub(crate) fn build_url(&self) -> Url {
        let filename =
            utf8_percent_encode(&self.filename.to_string_lossy(), NON_ALPHANUMERIC).to_string();
        let mut url = Url::parse(&format!("sqlite://{}", filename)).unwrap();

        let mode = match (self.in_memory, self.create_if_missing, self.read_only) {
            (true, _, _) => "memory",
            (false, true, _) => "rwc",
            (false, false, true) => "ro",
            (false, false, false) => "rw",
        };
        url.query_pairs_mut().append_pair("mode", mode);

        let cache = match self.shared_cache {
            true => "shared",
            false => "private",
        };
        url.query_pairs_mut().append_pair("cache", cache);

        url.query_pairs_mut()
            .append_pair("immutable", &self.immutable.to_string());

        if let Some(vfs) = &self.vfs {
            url.query_pairs_mut().append_pair("vfs", &vfs);
        }

        url
    }
}

Review comment (bug):
```suggestion
        let mut url = Url::parse(&format!("sqlite://{}", filename))
            .expect("BUG: generated un-parseable URL");
```

Code after:
                        _ => {
                            return Err(Error::Configuration(
                                format!("unknown value {value:?} for `immutable`").into(),
                            ));
                        }
                    },

                    "vfs" => options.vfs = Some(Cow::Owned(value.into_owned())),

                    _ => {
                        return Err(Error::Configuration(
                            format!("unknown query parameter `{key}` while parsing connection URL")
                                .into(),
                        ));
                    }
                }
            }
        }

        Ok(options)
    }

    pub(crate) fn build_url(&self) -> Url {
        let filename =
            utf8_percent_encode(&self.filename.to_string_lossy(), NON_ALPHANUMERIC).to_string();
        let mut url =
            Url::parse(&format!("sqlite://{}", filename)).expect("BUG: generated un-parseable URL");

        let mode = match (self.in_memory, self.create_if_missing, self.read_only) {
            (true, _, _) => "memory",
            (false, true, _) => "rwc",
            (false, false, true) => "ro",
            (false, false, false) => "rw",
        };
        url.query_pairs_mut().append_pair("mode", mode);

        let cache = match self.shared_cache {
            true => "shared",
            false => "private",
        };
        url.query_pairs_mut().append_pair("cache", cache);

        url.query_pairs_mut()
            .append_pair("immutable", &self.immutable.to_string());

        if let Some(vfs) = &self.vfs {
            url.query_pairs_mut().append_pair("vfs", &vfs);
        }

        url
    }