@@ -13,8 +13,8 @@ use crate::{
1313use quick_xml:: { Reader , events:: Event } ;
1414
1515use super :: common:: {
16- EVENT_BUFFER_CAPACITY , FromAttributes , LimitedCollectionExt , bytes_to_string, init_feed ,
17- read_text, skip_element, skip_to_end,
16+ EVENT_BUFFER_CAPACITY , FromAttributes , LimitedCollectionExt , bytes_to_string, check_depth ,
17+ init_feed , is_content_tag , is_dc_tag , is_media_tag , read_text, skip_element, skip_to_end,
1818} ;
1919
2020/// Parse Atom 1.0 feed from raw bytes
@@ -107,12 +107,7 @@ fn parse_feed_element(
107107 } ;
108108
109109 * depth += 1 ;
110- if * depth > limits. max_nesting_depth {
111- return Err ( FeedError :: InvalidFormat ( format ! (
112- "XML nesting depth {depth} exceeds maximum {}" ,
113- limits. max_nesting_depth
114- ) ) ) ;
115- }
110+ check_depth ( * depth, limits. max_nesting_depth ) ?;
116111
117112 let element = e. to_owned ( ) ;
118113 // Use name() instead of local_name() to preserve namespace prefixes
@@ -266,12 +261,7 @@ fn parse_entry(
266261 } ;
267262
268263 * depth += 1 ;
269- if * depth > limits. max_nesting_depth {
270- return Err ( FeedError :: InvalidFormat ( format ! (
271- "XML nesting depth {depth} exceeds maximum {}" ,
272- limits. max_nesting_depth
273- ) ) ) ;
274- }
264+ check_depth ( * depth, limits. max_nesting_depth ) ?;
275265
276266 let element = e. to_owned ( ) ;
277267 // Use name() instead of local_name() to preserve namespace prefixes
@@ -468,12 +458,7 @@ fn parse_person(
468458 match reader. read_event_into ( buf) {
469459 Ok ( Event :: Start ( e) ) => {
470460 * depth += 1 ;
471- if * depth > limits. max_nesting_depth {
472- return Err ( FeedError :: InvalidFormat ( format ! (
473- "XML nesting depth {} exceeds maximum {}" ,
474- depth, limits. max_nesting_depth
475- ) ) ) ;
476- }
461+ check_depth ( * depth, limits. max_nesting_depth ) ?;
477462
478463 match e. local_name ( ) . as_ref ( ) {
479464 b"name" => name = Some ( read_text ( reader, buf, limits) ?) ,
@@ -568,12 +553,7 @@ fn parse_atom_source(
568553 match reader. read_event_into ( buf) {
569554 Ok ( Event :: Start ( e) | Event :: Empty ( e) ) => {
570555 * depth += 1 ;
571- if * depth > limits. max_nesting_depth {
572- return Err ( FeedError :: InvalidFormat ( format ! (
573- "XML nesting depth {} exceeds maximum {}" ,
574- depth, limits. max_nesting_depth
575- ) ) ) ;
576- }
556+ check_depth ( * depth, limits. max_nesting_depth ) ?;
577557
578558 let element = e. to_owned ( ) ;
579559 // Use name() instead of local_name() to preserve namespace prefixes
@@ -605,36 +585,6 @@ fn parse_atom_source(
605585 Ok ( Source { title, link, id } )
606586}
607587
608- /// Check if element name matches a Dublin Core namespace tag
609- #[ inline]
610- fn is_dc_tag ( name : & [ u8 ] ) -> Option < & str > {
611- if name. starts_with ( b"dc:" ) {
612- std:: str:: from_utf8 ( & name[ 3 ..] ) . ok ( )
613- } else {
614- None
615- }
616- }
617-
618- /// Check if element name matches a Content namespace tag
619- #[ inline]
620- fn is_content_tag ( name : & [ u8 ] ) -> Option < & str > {
621- if name. starts_with ( b"content:" ) {
622- std:: str:: from_utf8 ( & name[ 8 ..] ) . ok ( )
623- } else {
624- None
625- }
626- }
627-
628- /// Check if element name matches a Media RSS namespace tag
629- #[ inline]
630- fn is_media_tag ( name : & [ u8 ] ) -> Option < & str > {
631- if name. starts_with ( b"media:" ) {
632- std:: str:: from_utf8 ( & name[ 6 ..] ) . ok ( )
633- } else {
634- None
635- }
636- }
637-
638588#[ cfg( test) ]
639589mod tests {
640590 use super :: * ;
0 commit comments