Skip to content

🛠️ Validation of field names  #1197

@de-sh

Description

@de-sh
Contributor

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)

Activity

7h3cyb3rm0nk

7h3cyb3rm0nk commented on Feb 20, 2025

@7h3cyb3rm0nk
Contributor

Hey, I would like to work on this issue, can this issue be assigned to me, thanks!

added a commit that references this issue on Mar 2, 2025
887a63f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @de-sh@7h3cyb3rm0nk

    Issue actions

      :hammer_and_wrench: Validation of field names · Issue #1197 · parseablehq/parseable