diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-12-12 11:31:51 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-12-12 11:32:48 +0000 |
| commit | 6f45aa9937602f3d03cd83cfb5fb3c541fac4adf (patch) | |
| tree | c64277a455b0b8c07c4e501a0716f16365b88c33 /src/bin/git_remote_nostr/push.rs | |
| parent | 2b49a548169bf9bc3a3ef667a7e952e31e878bab (diff) | |
fix: defend against empty`tags`
prevent a panic when tags are of an unexpect length
Diffstat (limited to 'src/bin/git_remote_nostr/push.rs')
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 15 |
1 files changed, 11 insertions, 4 deletions
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( | |||
| 1010 | .iter() | 1010 | .iter() |
| 1011 | .filter(|e| { | 1011 | .filter(|e| { |
| 1012 | e.tags.iter().any(|t| { | 1012 | e.tags.iter().any(|t| { |
| 1013 | t.as_slice()[0].eq("commit") | 1013 | t.as_slice().len() > 1 |
| 1014 | && t.as_slice()[0].eq("commit") | ||
| 1014 | && t.as_slice()[1].eq(&parent.id().to_string()) | 1015 | && t.as_slice()[1].eq(&parent.id().to_string()) |
| 1015 | }) | 1016 | }) |
| 1016 | }) | 1017 | }) |
| @@ -1034,7 +1035,9 @@ async fn get_merged_proposals_info( | |||
| 1034 | .iter() | 1035 | .iter() |
| 1035 | .filter(|e| { | 1036 | .filter(|e| { |
| 1036 | e.tags.iter().any(|t| { | 1037 | e.tags.iter().any(|t| { |
| 1037 | t.as_slice()[0].eq("commit") && t.as_slice()[1].eq(&commit_hash.to_string()) | 1038 | t.as_slice().len() > 1 |
| 1039 | && t.as_slice()[0].eq("commit") | ||
| 1040 | && t.as_slice()[1].eq(&commit_hash.to_string()) | ||
| 1038 | }) | 1041 | }) |
| 1039 | }) | 1042 | }) |
| 1040 | .collect::<Vec<&Event>>() | 1043 | .collect::<Vec<&Event>>() |
| @@ -1228,7 +1231,11 @@ async fn get_proposal_and_revision_root_from_patch( | |||
| 1228 | git_repo: &Repo, | 1231 | git_repo: &Repo, |
| 1229 | patch: &Event, | 1232 | patch: &Event, |
| 1230 | ) -> Result<(EventId, Option<EventId>)> { | 1233 | ) -> Result<(EventId, Option<EventId>)> { |
| 1231 | let proposal_or_revision = if patch.tags.iter().any(|t| t.as_slice()[1].eq("root")) { | 1234 | let proposal_or_revision = if patch |
| 1235 | .tags | ||
| 1236 | .iter() | ||
| 1237 | .any(|t| t.as_slice().len() > 1 && t.as_slice()[1].eq("root")) | ||
| 1238 | { | ||
| 1232 | patch.clone() | 1239 | patch.clone() |
| 1233 | } else { | 1240 | } else { |
| 1234 | let proposal_or_revision_id = EventId::parse( | 1241 | let proposal_or_revision_id = EventId::parse( |
| @@ -1260,7 +1267,7 @@ async fn get_proposal_and_revision_root_from_patch( | |||
| 1260 | if proposal_or_revision | 1267 | if proposal_or_revision |
| 1261 | .tags | 1268 | .tags |
| 1262 | .iter() | 1269 | .iter() |
| 1263 | .any(|t| t.as_slice()[1].eq("revision-root")) | 1270 | .any(|t| t.as_slice().len() > 1 && t.as_slice()[1].eq("revision-root")) |
| 1264 | { | 1271 | { |
| 1265 | Ok(( | 1272 | Ok(( |
| 1266 | EventId::parse( | 1273 | EventId::parse( |