gandres / pwm

Automatically exported from code.google.com/p/pwm
0 stars 0 forks source link

Form value regexp validation kicks in on empty values #382

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Inside the Configuration Manager, setup a form configuration with an 
optional attribute with a regular expression to validate it (i.e. Update 
profile Form)
2. In the frontend go to update profile and clear the value of that optional 
attribute and try to save it

What is the expected output? What do you see instead?
Expected output is that PWM would accept the empty value (and clears it in 
LDAP). Instead the Validator kicks in to validate the form value with the 
regular expression.

I wrote a small patch to validate the form value with the regexp only when the 
string length of the value is > 0. This should be ok, because required values 
are always tested for a string length >0 in advance.

My patch:

Index: pwm/servlet/src/password/pwm/config/FormConfiguration.java
===================================================================
--- pwm/servlet/src/password/pwm/config/FormConfiguration.java  (revision 550)
+++ pwm/servlet/src/password/pwm/config/FormConfiguration.java  (working copy)
@@ -283,7 +283,7 @@
             throw new PwmDataValidationException(error);
         }

-        if (value != null && this.getRegex() != null && 
this.getRegex().length() > 0) {
+        if (value != null && value.length() > 0 && this.getRegex() != null && 
this.getRegex().length() > 0) {
             if (!value.matches(this.getRegex())) {
                 final String configuredErrorMessage = this.getRegexError(locale);
                 final ErrorInformation error = new ErrorInformation(PwmError.ERROR_FIELD_REGEX_NOMATCH, null, configuredErrorMessage, new String[]{getLabel(locale)});

All the best,

Sebastiaan

Original issue reported on code.google.com by sebastia...@gmail.com on 3 May 2013 at 8:45

GoogleCodeExporter commented 9 years ago
And hereby the patch file

Original comment by sebastia...@gmail.com on 3 May 2013 at 2:02

Attachments:

GoogleCodeExporter commented 9 years ago
Fixed in revision 552. Thanks for contributing!

Original comment by menno.pi...@gmail.com on 4 May 2013 at 7:48