Closed
Description
The current implementation doesn't validate field names when processing StaticSchema
. Consider:
- Empty field names should be rejected
- Duplicate field names should be detected
Add validation before processing fields:
+ // Validate field names
+ let mut seen_fields = std::collections::HashSet::new();
+ for (field_name, _) in &fields {
+ if field_name.is_empty() {
+ return Err(StaticSchemaError::EmptyFieldName);
+ }
+ if !seen_fields.insert(field_name) {
+ return Err(StaticSchemaError::DuplicateField(field_name.clone()));
+ }
+ }
+
for (field_name, field_type) in fields {
Add the new error variants:
#[error("field name cannot be empty")]
EmptyFieldName,
#[error("duplicate field name: {0}")]
DuplicateField(String),
Originally posted by @coderabbitai[bot] in #1192 (comment)