Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/589 fix truncation error #590

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- [589](https://github.com/thoth-pub/thoth/issues/589) - Truncation of `short_abstract` in Thoth ONIX results in Invalid UTF-8 sequences

## [[0.12.0]](https://github.com/thoth-pub/thoth/releases/tag/v0.12.0) - 2024-03-14
### Removed
Expand Down
9 changes: 7 additions & 2 deletions thoth-export-server/src/xml/onix3_thoth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,13 @@ impl XmlElementBlock<Onix3Thoth> for Work {
})?;
write_element_block("CollateralDetail", w, |w| {
if let Some(mut short_abstract) = self.short_abstract.clone() {
// Short description field may not exceed 350 characters
short_abstract.truncate(350);
// Short description field may not exceed 350 characters.
// Ensure that the string is truncated at a valid UTF-8 boundary
// by finding the byte index of the 350th character and then truncating
// the string at that index, to avoid creating invalid UTF-8 sequences.
if let Some((byte_index, _)) = short_abstract.char_indices().nth(350) {
short_abstract.truncate(byte_index);
}
write_element_block("TextContent", w, |w| {
// 02 Short description
write_element_block("TextType", w, |w| {
Expand Down
Loading