From 6f45aa9937602f3d03cd83cfb5fb3c541fac4adf Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 12 Dec 2024 11:31:51 +0000 Subject: fix: defend against empty`tags` prevent a panic when tags are of an unexpect length --- src/bin/git_remote_nostr/push.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/bin/git_remote_nostr/push.rs') diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index 6116fe2..4066312 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs @@ -1010,7 +1010,8 @@ async fn get_merged_proposals_info( .iter() .filter(|e| { e.tags.iter().any(|t| { - t.as_slice()[0].eq("commit") + t.as_slice().len() > 1 + && t.as_slice()[0].eq("commit") && t.as_slice()[1].eq(&parent.id().to_string()) }) }) @@ -1034,7 +1035,9 @@ async fn get_merged_proposals_info( .iter() .filter(|e| { e.tags.iter().any(|t| { - t.as_slice()[0].eq("commit") && t.as_slice()[1].eq(&commit_hash.to_string()) + t.as_slice().len() > 1 + && t.as_slice()[0].eq("commit") + && t.as_slice()[1].eq(&commit_hash.to_string()) }) }) .collect::>() @@ -1228,7 +1231,11 @@ async fn get_proposal_and_revision_root_from_patch( git_repo: &Repo, patch: &Event, ) -> Result<(EventId, Option)> { - let proposal_or_revision = if patch.tags.iter().any(|t| t.as_slice()[1].eq("root")) { + let proposal_or_revision = if patch + .tags + .iter() + .any(|t| t.as_slice().len() > 1 && t.as_slice()[1].eq("root")) + { patch.clone() } else { let proposal_or_revision_id = EventId::parse( @@ -1260,7 +1267,7 @@ async fn get_proposal_and_revision_root_from_patch( if proposal_or_revision .tags .iter() - .any(|t| t.as_slice()[1].eq("revision-root")) + .any(|t| t.as_slice().len() > 1 && t.as_slice()[1].eq("revision-root")) { Ok(( EventId::parse( -- cgit v1.2.3