Closed jasquat closed 2 weeks ago
spiffworkflow-frontend/src/rjsf/custom_widgets/NumericRangeField/NumericRangeField.tsx (1)
`86-88`: Ensure the regex `matchNumberRegex` is robust enough for number validation.Verification successful
--- The regex pattern `matchNumberRegex` used in the `parseNumberString` function is defined as `/^[0-9,.-]*$/`. This pattern matches any string composed entirely of the characters 0-9, comma, period, and hyphen. It allows for an empty string as well due to the `*` quantifier, which matches zero or more of the preceding element. ### Analysis of the Regex Pattern: 1. **Numeric Characters**: It correctly includes all numeric characters (0-9). 2. **Decimal and Negative Values**: The inclusion of the period (`.`) and hyphen (`-`) allows for the representation of decimal and negative numbers, respectively. 3. **Commas**: The inclusion of commas supports number formatting in some locales, which use commas as thousand separators. 4. **Potential Issues**: - The regex does not enforce the correct placement of commas, periods, or hyphens. For example, it would incorrectly validate strings like `12.34.56`, `--123`, or `1,2,3,4`. - It allows multiple commas, periods, and hyphens anywhere in the string, which might not be intended. Given this analysis, while the regex does allow a broad range of numeric representations, it might not strictly enforce the correct format of numbers, especially concerning the placement and repetition of special characters like the decimal point and hyphen. This could lead to potential issues with data validation if strict number formatting is required. ### Conclusion: The regex `matchNumberRegex` provides a basic level of numeric validation but lacks precision in enforcing correct numeric formats. Depending on the application's requirements for number input validation, this might or might not be sufficient. If strict validation is necessary, the regex should be refined to enforce correct placements of commas, periods, and hyphens. - **Recommendation**: Review the requirements for number validation in the application and consider refining the regex if stricter validation is needed.Scripts Executed
The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify the robustness of `matchNumberRegex` used in `parseNumberString` function. # Find the definition of `matchNumberRegex` and display its pattern. rg --files-with-matches --type typescript $'export const matchNumberRegex =' | xargs cat ``` Length of output: 124 --- --- Script: ```shell #!/bin/bash # Description: Verify the robustness of `matchNumberRegex` used in `parseNumberString` function. # Correcting the file type specification to search within TypeScript files. rg --files-with-matches 'export const matchNumberRegex =' *.ts* | xargs cat ``` Length of output: 125 --- --- Script: ```shell #!/bin/bash # Description: Verify the robustness of `matchNumberRegex` used in `parseNumberString` function. # Adjusting the script to search recursively without specifying file patterns incorrectly. rg --files-with-matches 'export const matchNumberRegex =' --glob '*.ts*' | xargs cat ``` Length of output: 9621
Addresses https://github.com/sartography/spiff-arena/issues/647#issuecomment-2089568978
This adds in some conditionals so the numeric range field is not invalidated when it is unset and not required. It also cleans up the conditionals a bit and allows for text to be set in the state. Before the text would go away on reload which seemed confusing to me so set the state and let it run through validations on submit seems more intuitive to me.