Skip to content

Commit

Permalink
bam/record/name: Trim trailing NUL when converting to an alignment re…
Browse files Browse the repository at this point in the history
…cord name buffer

Fixes #254.
  • Loading branch information
zaeleus committed Apr 19, 2024
1 parent 7ab21e4 commit 5ac69f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 9 additions & 0 deletions noodles-bam/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## Unreleased

### Fixed

* bam/record/name: Trim trailing `NUL` when converting to an alignment record
name buffer ([#254]).

[#254]: https://github.com/zaeleus/noodles/issues/254

## 0.59.0 - 2024-04-04

### Changed
Expand Down
17 changes: 16 additions & 1 deletion noodles-bam/src/record/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'a> fmt::Debug for Name<'a> {

impl<'a> From<Name<'a>> for sam::alignment::record_buf::Name {
fn from(name: Name<'a>) -> Self {
Self::from(name.as_ref())
Self::from(name.as_bytes())
}
}

Expand All @@ -59,4 +59,19 @@ mod tests {
let name = Name::new(b"r0");
assert_eq!(name.as_bytes(), b"r0");
}

#[test]
fn test_from_name_for_sam_alignment_record_buf_name() {
use noodles_sam::alignment::record_buf::Name as NameBuf;

let expected = NameBuf::from(b"r0");

let name = Name::new(b"r0\x00");
let actual = NameBuf::from(name);
assert_eq!(actual, expected);

let name = Name::new(b"r0");
let actual = NameBuf::from(name);
assert_eq!(actual, expected);
}
}

0 comments on commit 5ac69f8

Please sign in to comment.