You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The validateFileUploaded function contains two identical checks to skip validation for optional empty fields. The second block is redundant and can be removed to reduce code duplication.
// skip validation if not required and value is emptyif(validation.required!==true&&(fieldValue===undefined||fieldValue===""||fieldValue===null)){returnerrors;}// requiredif(validation.required===true&&(fieldValue===undefined||fieldValue===""||fieldValue===null)){errors.push({field_id: `${question.id}`,message: `This field is required`,});returnerrors;}// skip validation if not required and value is emptyif(validation.required!==true&&(fieldValue===undefined||fieldValue===""||fieldValue===null)){returnerrors;}
Using truthy checks for validation.minValue and validation.maxValue will skip validation when bounds are zero. Consider using explicit undefined or null checks to ensure zero is handled correctly.
// check valueif(validation.minValue&&fieldValue<validation.minValue){errors.push({field_id: `${question.id}`,message: `Must be more than or equal to ${validation.minValue}`,});}if(validation.maxValue&&fieldValue>validation.maxValue){errors.push({field_id: `${question.id}`,message: `Must be less than or equal to ${validation.maxValue}`,});
The new conditional wraps file path assignment for non-empty uploads only. Confirm that non-file question types and empty file fields are still populated correctly in dataToSave.
-// skip validation if not required and value is empty+// skip validation if not required and value is empty or whitespace
if (
validation.required !== true &&
- (fieldValue === undefined || fieldValue === "" || fieldValue === null)+ (fieldValue == null || (typeof fieldValue === "string" && fieldValue.trim() === ""))
) {
return errors;
}
Suggestion importance[1-10]: 6
__
Why: Enhancing the skip logic to trim whitespace avoids improper validation of blank strings, improving data integrity.
Low
Extract skip logic helper
Extract the repeated optional‐skip logic into a shared helper (e.g. shouldSkipValidation(validation.required, fieldValue)) to reduce duplication and ensure consistency across all validators.
Why: Using != null plus !== "" makes the condition more concise without altering its semantics.
Low
Possible issue
Remove redundant skip block
Remove the duplicate optional‐skip block immediately before the try in validateFileUploaded. Only the first pre-check is needed, so deleting the second prevents bypassing post-required validation logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Fix some bug in validation which are:
PR Type
Bug fix
Description
Skip validation for optional empty fields
Restrict file path rewrite to non-empty uploads
Type annotate errors arrays in validators
Enable Firestore ignoreUndefinedProperties setting
Changes walkthrough 📝
firebase.ts
Enable ignoring undefined Firestore propertiesfunctions/src/config/firebase.ts
application_controller.ts
Refine form validation and file upload logicfunctions/src/controllers/application_controller.ts