@@ -19,14 +19,15 @@ impl ContentTypeRule {
1919 & self ,
2020 doc : & CatalystSignedDocument ,
2121 ) -> anyhow:: Result < bool > {
22- let Ok ( content_type) = doc. doc_content_type ( ) else {
23- doc. report ( ) . missing_field (
24- "content-type" ,
25- "Cannot get a content type field during the field validation" ,
26- ) ;
27- return Ok ( false ) ;
28- } ;
2922 if let Self :: Specified { exp } = & self {
23+ let Ok ( content_type) = doc. doc_content_type ( ) else {
24+ doc. report ( ) . missing_field (
25+ "content-type" ,
26+ "Cannot get a content type field during the field validation" ,
27+ ) ;
28+ return Ok ( false ) ;
29+ } ;
30+
3031 if content_type != * exp {
3132 doc. report ( ) . invalid_value (
3233 "content-type" ,
@@ -37,6 +38,16 @@ impl ContentTypeRule {
3738 return Ok ( false ) ;
3839 }
3940 }
41+ if let Self :: NotSpecified = & self {
42+ if let Ok ( content_type) = doc. doc_meta ( ) . content_type ( ) {
43+ doc. report ( ) . unknown_field (
44+ "content-type" ,
45+ & content_type. to_string ( ) . as_str ( ) ,
46+ & format ! ( "document does not expect to have the content type field" ) ,
47+ ) ;
48+ return Ok ( false ) ;
49+ }
50+ }
4051 let Ok ( content) = doc. decoded_content ( ) else {
4152 doc. report ( ) . functional_validation (
4253 "Invalid Document content, cannot get decoded bytes" ,
0 commit comments