Skip to content

🛠️ Validation of field names  #1197

Closed
@de-sh

Description

@de-sh

The current implementation doesn't validate field names when processing StaticSchema. Consider:

  1. Empty field names should be rejected
  2. 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)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions