Skip to content

Commit 756538e

Browse files
TheAwitebyukibtc
authored andcommitted
nostr: fix nip22::extract_root to handle uppercase tags when is_root is true
Fixes the `nip22::extract_root` function by ensuring it properly handles uppercase and lowercase tags (`k`,`e`,`a`,`i`) when `is_root` is `true`. The issue occurred because `nip22::extract_{kind,event,coordinate,external}` enforced lowercase kinds even for root cases. Pull-Request: #876 Signed-off-by: Awiteb <[email protected]> Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 7089339 commit 756538e

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
### Fixed
5555

5656
- nostr: handle `A` and `E` standard tags ([awiteb] at https://github.com/rust-nostr/nostr/pull/870)
57+
- nostr: fix `nip22::extract_root` to handle uppercase tags when `is_root` is true ([awiteb] at https://github.com/rust-nostr/nostr/pull/876)
5758

5859
### Deprecated
5960

crates/nostr/src/nips/nip22.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
use crate::nips::nip01::Coordinate;
1010
use crate::nips::nip73::ExternalContentId;
11-
use crate::{Event, EventId, Kind, PublicKey, RelayUrl, TagKind, TagStandard, Url};
11+
use crate::{Alphabet, Event, EventId, Kind, PublicKey, RelayUrl, TagKind, TagStandard, Url};
1212

1313
/// Borrowed comment extracted data
1414
pub enum Comment<'a> {
@@ -98,7 +98,7 @@ fn check_return<T>(val: T, is_root: bool, uppercase: bool) -> Option<T> {
9898
fn extract_kind(event: &Event, is_root: bool) -> Option<&Kind> {
9999
event
100100
.tags
101-
.filter_standardized(TagKind::k())
101+
.filter_standardized(TagKind::single_letter(Alphabet::K, is_root))
102102
.find_map(|tag| match tag {
103103
TagStandard::Kind { kind, uppercase } => check_return(kind, is_root, *uppercase),
104104
_ => None,
@@ -116,7 +116,7 @@ fn extract_event(
116116
) -> Option<(&EventId, Option<&RelayUrl>, Option<&PublicKey>)> {
117117
event
118118
.tags
119-
.filter_standardized(TagKind::e())
119+
.filter_standardized(TagKind::single_letter(Alphabet::E, is_root))
120120
.find_map(|tag| match tag {
121121
TagStandard::Event {
122122
event_id,
@@ -141,7 +141,7 @@ fn extract_event(
141141
fn extract_coordinate(event: &Event, is_root: bool) -> Option<(&Coordinate, Option<&RelayUrl>)> {
142142
event
143143
.tags
144-
.filter_standardized(TagKind::a())
144+
.filter_standardized(TagKind::single_letter(Alphabet::A, is_root))
145145
.find_map(|tag| match tag {
146146
TagStandard::Coordinate {
147147
coordinate,
@@ -161,7 +161,7 @@ fn extract_coordinate(event: &Event, is_root: bool) -> Option<(&Coordinate, Opti
161161
fn extract_external(event: &Event, is_root: bool) -> Option<(&ExternalContentId, Option<&Url>)> {
162162
event
163163
.tags
164-
.filter_standardized(TagKind::i())
164+
.filter_standardized(TagKind::single_letter(Alphabet::I, is_root))
165165
.find_map(|tag| match tag {
166166
TagStandard::ExternalContent {
167167
content,

0 commit comments

Comments
 (0)