Fix Registry: Object ids are parsed as numbers
This commit is contained in:
@@ -300,8 +300,8 @@ impl MapItem for Id {
|
||||
Id::from_str(value).ok()
|
||||
}
|
||||
|
||||
fn try_from_integer(_: u64) -> Option<Self> {
|
||||
None
|
||||
fn try_from_integer(value: u64) -> Option<Self> {
|
||||
Id::from_str(&value.to_string()).ok()
|
||||
}
|
||||
|
||||
fn into_string(self) -> Cow<'static, str> {
|
||||
@@ -417,3 +417,28 @@ impl<T: MapItem> IntoIterator for Map<T> {
|
||||
self.0.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{jmap::JsonPointerPatch, schema::prelude::Property};
|
||||
use jmap_tools::JsonPointer;
|
||||
|
||||
fn patch_member(ptr_str: &str) -> Map<Id> {
|
||||
let mut map = Map::<Id>::default();
|
||||
let ptr = JsonPointer::<Property>::parse(ptr_str);
|
||||
let pointer = JsonPointerPatch::new(&ptr);
|
||||
map.patch(pointer, Value::Bool(true)).expect("patch failed");
|
||||
map
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn patch_map_id_digit_keys() {
|
||||
for id in [0u64, 28, 29, 70, 861, 954, 957, 30554] {
|
||||
let id = Id::new(id);
|
||||
let key = id.as_string();
|
||||
let map = patch_member(&key);
|
||||
assert_eq!(map.0, vec![id], "id {} via key '{key}'", id.id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user