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 new pattern validation creates a new RegExp on every call and does not handle invalid patterns. Consider validating or compiling regexes once and adding error handling for malformed patterns.
if(validation.pattern){constregex=newRegExp(validation.pattern);if(!regex.test(fieldValue)){errors.push({field_id: `${question.id}`,message: `Not a valid ${question.text}.`,});}
Pattern validation runs even when fieldValue is empty or null. You may want to skip regex checks when the value is not provided or when required is false.
// validate patternif(validation.pattern){constregex=newRegExp(validation.pattern);if(!regex.test(fieldValue)){errors.push({field_id: `${question.id}`,message: `Not a valid ${question.text}.`,});}}
Question.id was changed from optional to required and state/placeholder were added. Ensure all existing consumers provide these fields to avoid compilation or runtime errors.
id: string;
order: number;
text: string;
type: QUESTION_TYPE;
validation: ValidationTypeMap[Question["type"]];
placeholder?: string;
options?: string[];// for dropdown only
state: APPLICATION_STATES;
if (validation.pattern) {
- const regex = new RegExp(validation.pattern);- if (!regex.test(fieldValue)) {+ try {+ const regex = new RegExp(validation.pattern);+ if (!regex.test(fieldValue)) {+ errors.push({+ field_id: `${question.id}`,+ message: `Not a valid ${question.text}.`,+ });+ }+ } catch {+ // invalid pattern, skip this check+ }+}
Suggestion importance[1-10]: 8
__
Why: Wrapping the regex construction and test in a try-catch prevents invalid patterns from throwing errors at runtime and crashing the validation logic.
Medium
Guard regex test by type
Ensure fieldValue is actually a string before running the regex test to avoid type errors on null or non-string inputs.
-const regex = new RegExp(validation.pattern);+const regex = new RegExp(`^${validation.pattern}$`);
Suggestion importance[1-10]: 5
__
Why: Anchoring the pattern with ^ and $ enforces a full-string match instead of a substring match, improving the accuracy of the validation.
Low
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.
PR Type
Enhancement
Description
Introduce regex-based pattern validation for strings
Extend StringValidation with optional
patternfieldAdd new
CONFIRMED_RSVPapplication statusNormalize enum string values to lowercase variants
Changes walkthrough 📝
application_controller.ts
Add pattern validation to stringsfunctions/src/controllers/application_controller.ts
application_types.ts
Enhance application type definitionsfunctions/src/types/application_types.ts
CONFIRMED_RSVPstatusAPPLICATION_STATESvaluesStringValidationwithpatternQuestion.idrequired and addedplaceholder