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

Fixing a bug that will allow a value of '0' to bypass validation. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leadoux
Copy link

@leadoux leadoux commented Nov 25, 2020

Hi Matt.
We use your gravityforms-regex-validation plugin - thanks.
I have found a small bug where a value of 0 will not pass as True for !empty($value), and then regex validation does not happen, allowing '0' to pass strait past the regex - obviously not a desireable outcome.
Please reveiw my simple fix and consider rolling it into your code to fix this issue for all.
Regards...Adam.

@@ -82,7 +82,7 @@ function ToggleInputRegEx(isInit){
// validate submitted data against provided regex
public function validate($result, $value, $form, $field) {
// if validation has passed so far, and regex validation is enabled, and a pattern was provided, and a value was provided
if ($result['is_valid'] && $field['regexValidation'] && !empty($field['regexPattern']) && !empty($value)) {
if ($result['is_valid'] && $field['regexValidation'] && !empty($field['regexPattern']) && ( strlen($value) != 0 )) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion @leadoux! This is a little cleaner, and should work as well--look good to you?

Suggested change
if ($result['is_valid'] && $field['regexValidation'] && !empty($field['regexPattern']) && ( strlen($value) != 0 )) {
if ($result['is_valid'] && $field['regexValidation'] && !empty($field['regexPattern']) && strlen($value)) {

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

Successfully merging this pull request may close these issues.

None yet

2 participants