Skip to content

Fix human-readable serde deserialization of CollationSpecialPrimaries - #8551

Merged
Manishearth merged 2 commits into
unicode-org:mainfrom
Manishearth:fix-collator-special-primaries-serde
Oct 7, 2026
Merged

Manishearth merged 2 commits into
unicode-org:mainfrom
Manishearth:fix-collator-special-primaries-serde

Conversation

@Manishearth

Copy link
Copy Markdown
Member

CollationSpecialPrimaries::serialize renames the concatenated field to "last_primaries", whereas CollationSpecialPrimaries::deserialize omitted rename = "last_primaries" and borrowed &'data ZeroSlice, which fails to deserialize from human-readable JSON sequences.

Add rename = "last_primaries" and deserialize via ZeroVec<'data, u16> so both zero-copy binary formats and human-readable JSON formats round-trip.

Changelog

icu_collator: Fix human-readable serde deserialization of CollationSpecialPrimaries

…ecialPrimaries

CollationSpecialPrimaries::serialize renames the concatenated field to
"last_primaries", whereas CollationSpecialPrimaries::deserialize omitted
rename = "last_primaries" and borrowed &'data ZeroSlice<u16>, which fails to
deserialize from human-readable JSON sequences.

Add rename = "last_primaries" and deserialize via ZeroVec<'data, u16> so
both zero-copy binary formats and human-readable JSON formats round-trip.
@Manishearth
Manishearth requested review from a team, echeran and hsivonen as code owners October 6, 2026 22:01
Comment thread components/collator/src/provider.rs Outdated
Comment on lines +636 to 656
use alloc::borrow::Cow;
let (last_primaries, mut compressible_bytes) = match concatenated.into_cow() {
Cow::Borrowed(s) => {
let Some((l, c)) = s.split_at_checked(MaxVariable::VARIANT_COUNT) else {
return Err(serde::de::Error::custom("invalid"));
};
(
ZeroSlice::from_ule_slice(l).as_zerovec(),
ZeroSlice::from_ule_slice(c).as_zerovec(),
)
}
Cow::Owned(v) => {
let Some((l, c)) = v.split_at_checked(MaxVariable::VARIANT_COUNT) else {
return Err(serde::de::Error::custom("invalid"));
};
(
ZeroSlice::from_ule_slice(l).as_zerovec().into_owned(),
ZeroSlice::from_ule_slice(c).as_zerovec().into_owned(),
)
}
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this diff seems unrelated to the issue this PR addresses. why?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because now it might deserialize as owned.

@Manishearth
Manishearth merged commit a5a141d into unicode-org:main Oct 7, 2026
34 checks passed
@Manishearth
Manishearth deleted the fix-collator-special-primaries-serde branch October 7, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants