Skip to content

Commit

Permalink
use replace instead of trim for removing null bytes (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith authored Oct 4, 2023
1 parent f274d26 commit dec4b16
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/database/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl Database for Postgres {
for log in logs {
Self::store_event(&mut transaction, &self.events, log)
.await
.context("store_event")?;
.context(format!("store_event {:?}", log))?;
}

transaction.commit().await.context("commit")
Expand Down Expand Up @@ -335,9 +335,7 @@ impl Postgres {
.collect::<Vec<_>>(),
),
VisitValue::Value(AbiValue::Bytes(v)) => Box::new(v.to_owned()),
VisitValue::Value(AbiValue::String(v)) => {
Box::new(v.trim_matches('\0').to_string())
}
VisitValue::Value(AbiValue::String(v)) => Box::new(v.replace('\0', "")),
_ => unreachable!(),
};
(if in_array {
Expand Down Expand Up @@ -501,7 +499,7 @@ mod tests {
use super::*;

fn local_postgres_url() -> String {
format!("postgresql://{}@localhost", whoami::username())
"postgresql://arak@localhost".to_string()
}

async fn clear_database() {
Expand Down Expand Up @@ -564,7 +562,9 @@ event Event (
fields: vec![
AbiValue::Bool(true),
AbiValue::Bool(false),
AbiValue::String("zef with trailing null bytes\0".to_string()),
// Example taken from Erc1155Uri event at tx:
// 0x1174cad0a67be620255a206e5104ea1cadef3d300e0f2e2ab41483b249a67d2f
AbiValue::String("\0 \0\u{1}".to_string()),
],
..Default::default()
};
Expand Down

0 comments on commit dec4b16

Please sign in to comment.