File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -167,18 +167,36 @@ impl Record {
167167
168168 let mut s = String :: new ( ) ;
169169
170+ // DELETED prefix
170171 if self . deleted == Deleted :: Soft {
171172 s. push_str ( "DELETED" ) ;
172173 }
173174
175+ // HASH prefix
174176 if let Some ( ref h) = self . hash {
175- // Defensive check: only write well-formed hashes.
176177 if h. len ( ) == Self :: HASH_HEX_LEN && h. chars ( ) . all ( |c| c. is_ascii_hexdigit ( ) ) {
177178 s. push_str ( "HASH" ) ;
178179 s. push_str ( h) ;
180+ } else {
181+ return Err ( Error :: RecordDecode ( "invalid hash format" . into ( ) ) ) ;
179182 }
180183 }
181184
185+ // TYPE prefix
186+ if let Some ( ref ct) = self . content_type {
187+ if ct. is_empty ( ) || ct. contains ( '|' ) {
188+ return Err ( Error :: RecordDecode ( "invalid content type" . into ( ) ) ) ;
189+ }
190+ s. push_str ( "TYPE" ) ;
191+ s. push_str ( ct) ;
192+ s. push ( '|' ) ;
193+ }
194+
195+ // 4. Volumes (required)
196+ if self . volumes . is_empty ( ) {
197+ return Err ( Error :: RecordDecode ( "record has no volume entries" . into ( ) ) ) ;
198+ }
199+
182200 s. push_str ( & self . volumes . join ( "," ) ) ;
183201 Ok ( s. into_bytes ( ) )
184202 }
You can’t perform that action at this time.
0 commit comments