Skip to content

Commit

Permalink
Merge pull request #590 from thoth-pub/feature/589_fix_truncation_error
Browse files Browse the repository at this point in the history
Feature/589 fix truncation error
  • Loading branch information
ja573 authored Apr 8, 2024
2 parents eb973f3 + 1dabb2d commit 19418b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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

0 comments on commit 19418b7

Please sign in to comment.