Skip to content

Commit 1bb6568

Browse files
committed
Fix missing content type encoding in Record struct
1 parent 6e1bfb4 commit 1bb6568

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

minikv-core/src/record.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)