Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🛠️ Validation of field names #1197

Closed
de-sh opened this issue Feb 19, 2025 · 1 comment · Fixed by #1208
Closed

🛠️ Validation of field names #1197

de-sh opened this issue Feb 19, 2025 · 1 comment · Fixed by #1208
Assignees
Labels
good first issue Good for newcomers

Comments

@de-sh
Copy link
Contributor

de-sh commented Feb 19, 2025

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)

@de-sh de-sh added the good first issue Good for newcomers label Feb 19, 2025
@7h3cyb3rm0nk
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants