Merge branch 'mistrust_osstring_limitation' into 'main'

fs-mistrust: Document problems with non-UTF8 OsString in toml

See merge request tpo/core/arti!538
This commit is contained in:
Ian Jackson 2022-05-30 09:54:10 +00:00
commit 5327059775
2 changed files with 13 additions and 4 deletions

View File

@ -96,6 +96,11 @@ fn cur_groups() -> Vec<u32> {
/// `TrustedUser::Id(413)`.
/// * A string not starting with `:` (e.g., "jane") and the map `{ name = "jane" }`
/// correspond to `TrustedUser::Name("jane".into())`.
///
/// ## Limitations
///
/// Non-UTF8 usernames cannot currently be represented in all serde formats.
/// Notably, toml doesn't support them.
#[derive(Clone, Debug, educe::Educe, Eq, PartialEq)]
#[educe(Default)]
#[cfg_attr(

View File

@ -239,15 +239,19 @@ mod test {
fn os_string() {
// Try round-tripping a username that isn't UTF8.
use std::os::unix::ffi::OsStringExt as _;
let not_utf8 = OsString::from_vec(vec![1, 0, 0, 1]);
let not_utf8 = OsString::from_vec(vec![255, 254, 253, 252]);
assert!(not_utf8.to_str().is_none());
let chum = Chum {
handle: TrustedUser::Name(not_utf8.clone()),
team: TrustedGroup::Name(not_utf8),
};
let s = toml::to_string(&chum).unwrap();
let toml_obj: Chum = toml::from_str(&s).unwrap();
assert_eq!(&toml_obj, &chum);
// Alas, we cannot serialize an OsString in Toml. serde thinks that an
// OsString should be represented using `serialize_newtype_variant`, and
// the toml crate doesn't support that method.
//
//let toml_result = toml::to_string(&chum);
//assert!(toml_result.is_err());
let s = serde_json::to_string(&chum).unwrap();
let toml_obj: Chum = serde_json::from_str(&s).unwrap();