Skip to content

Commit

Permalink
Merge pull request #13 from thoth-pub/master
Browse files Browse the repository at this point in the history
Fix decoding issue on Field Display
  • Loading branch information
blackbeam authored Apr 24, 2023
2 parents c00cb31 + 431f3b8 commit 514d08a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
18 changes: 8 additions & 10 deletions src/field/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,14 @@ impl fmt::Display for Field<'_> {
}
_ => {
// variable data field
self.get_data::<[u8]>()
.iter()
.map(|&b| {
if b == SUBFIELD_DELIMITER {
'$'
} else {
b as char
}
})
.collect::<String>()
String::from_utf8_lossy(
&self
.get_data::<[u8]>()
.iter()
.map(|b| if *b == SUBFIELD_DELIMITER { 36 } else { *b })
.collect::<Vec<u8>>(),
)
.to_string()
}
};
write!(f, "{} {}", tag, field_data)
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,9 @@ mod tests {
builder
.add_fields(fields!(
data fields: [
b"264", b" 1", [
b'a' => "León, Spain",
],
b"245", b"00", [
b'a' => "Book title",
b'b' => "Book Subtitle",
Expand All @@ -1248,7 +1251,7 @@ mod tests {
.unwrap();
let record = builder.get_record().unwrap();

let expected = "=LDR 00191nam 2200085 i 4500\n=001 000000001\n=008 210128t20212021enka\\\\\\\\sb\\\\\\\\000\\0\\eng\\d\n=041 0 $aeng\n=100 1 $aAuthor Name\n=245 00$aBook title$bBook Subtitle\n".to_string();
let expected = "=LDR 00220nam 2200097 i 4500\n=001 000000001\n=008 210128t20212021enka\\\\\\\\sb\\\\\\\\000\\0\\eng\\d\n=041 0 $aeng\n=100 1 $aAuthor Name\n=245 00$aBook title$bBook Subtitle\n=264 1$aLeón, Spain\n".to_string();

assert_eq!(format!("{}", record), expected);
}
Expand Down

0 comments on commit 514d08a

Please sign in to comment.