mirror of
https://github.com/block/buzz.git
synced 2026-10-31 14:31:02 +00:00
fix(acp): align edit target validation
Signed-off-by: Larry <8cf5a83f590ec0955b11647d1c88f796a98e088c30a492c58e0e46c3026ae7a4@buzz.block.builderlab.xyz>
This commit is contained in:
@@ -1067,8 +1067,11 @@ pub fn edit_target_id(event: &Event) -> Option<String> {
|
||||
.then(|| {
|
||||
event.tags.iter().find_map(|tag| {
|
||||
let parts = tag.as_slice();
|
||||
(parts.len() == 2 && parts.first().map(String::as_str) == Some("e"))
|
||||
.then(|| parts[1].clone())
|
||||
(parts.first().map(String::as_str) == Some("e"))
|
||||
.then(|| parts.get(1))
|
||||
.flatten()
|
||||
.and_then(|target| nostr::EventId::from_hex(target).ok())
|
||||
.map(|target| target.to_hex())
|
||||
})
|
||||
})
|
||||
.flatten()
|
||||
@@ -5620,6 +5623,21 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edit_target_skips_malformed_e_tags_and_selects_first_valid_id() {
|
||||
let valid_target = "ab".repeat(32);
|
||||
let keys = Keys::generate();
|
||||
let event = EventBuilder::new(Kind::Custom(40003), "edited mention")
|
||||
.tags([
|
||||
nostr::Tag::parse(["e", "not-an-event-id"]).unwrap(),
|
||||
nostr::Tag::parse(["e", &valid_target]).unwrap(),
|
||||
])
|
||||
.sign_with_keys(&keys)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(edit_target_id(&event), Some(valid_target));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edit_of_top_level_anchors_original_message_in_rendered_prompt() {
|
||||
let original_id = "11".repeat(32);
|
||||
|
||||
Reference in New Issue
Block a user