Skip to content

Commit

Permalink
cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
nociza committed Apr 24, 2023
1 parent 872cf00 commit ff5ae88
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/dbc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ impl Database {
) -> Result<QueryResult, Error> {
let mut query = query.to_string();
for param in params {
let quoted_param = if let Some(_) = param.strip_prefix('\'') {
let quoted_param = if param.strip_prefix('\'').is_some() {
// If the parameter already has single quotes, don't add them again.
// This avoids SQL injection vulnerabilities when the parameter contains a quote.
param.to_string()
} else {
// If the parameter doesn't have single quotes, add them.
format!("'{}'", param)
};
query = query.replacen("?", quoted_param.as_str(), 1);
query = query.replacen('?', quoted_param.as_str(), 1);
}
self.execute_query(&query)
}
Expand Down
2 changes: 1 addition & 1 deletion src/dbc/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl dbc::Connection for SQLiteConnection {
}
Ok(dbc::QueryResult {
rows,
affected_rows: 0 as usize,
affected_rows: 0_usize,
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/mysql_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ fn _prepare_mysql_database() -> Result<dbc::Database, Error> {
#[serial_test::serial]
async fn test_mysql_simple_query() -> Result<(), Error> {
let database = _prepare_mysql_database()?;
Ok(common::test_simple_query(database).await?)
common::test_simple_query(database).await
}

#[tokio::test]
#[serial_test::serial]
async fn test_mysql_query_with_params() -> Result<(), Error> {
let database = _prepare_mysql_database()?;
Ok(common::test_query_with_params(database).await?)
common::test_query_with_params(database).await
}

#[tokio::test]
#[serial_test::serial]
async fn test_mysql_query_with_params_and_serialize() -> Result<(), Error> {
let database = _prepare_mysql_database()?;
Ok(common::test_query_with_params_and_serialize(database).await?)
common::test_query_with_params_and_serialize(database).await
}
6 changes: 3 additions & 3 deletions tests/sqlite_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ fn _prepare_sqlite_database() -> Result<dbc::Database, Error> {
#[serial_test::serial]
async fn test_sqlite_simple_query() -> Result<(), Error> {
let database = _prepare_sqlite_database()?;
Ok(common::test_simple_query(database).await?)
common::test_simple_query(database).await
}

#[tokio::test]
#[serial_test::serial]
async fn test_sqlite_query_with_params() -> Result<(), Error> {
let database = _prepare_sqlite_database()?;
Ok(common::test_query_with_params(database).await?)
common::test_query_with_params(database).await
}

#[tokio::test]
#[serial_test::serial]
async fn test_sqlite_query_with_params_and_serialize() -> Result<(), Error> {
let database = _prepare_sqlite_database()?;
Ok(common::test_query_with_params_and_serialize(database).await?)
common::test_query_with_params_and_serialize(database).await
}

0 comments on commit ff5ae88

Please sign in to comment.