Uploaded image for project: 'RichFaces'
  1. RichFaces
  2. RF-11531

Client side validation: regexp ignores whitespace at the beginning

    Details

      Description

      Let "[a-z].*" is expected regexp and input value is " a". The value shouldn't pass the validation, but it passes.

      This can be reproduced in Metamer:

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            bleathem Brian Leathem added a comment -

            The CSV behavior must the server side behavior validation behavior.

            Show
            bleathem Brian Leathem added a comment - The CSV behavior must the server side behavior validation behavior.
            Hide
            bleathem Brian Leathem added a comment -

            It's not just leading whitespace. Using an input value of "123a" the validation passes as well.

            Show
            bleathem Brian Leathem added a comment - It's not just leading whitespace. Using an input value of "123a" the validation passes as well.
            Hide
            bleathem Brian Leathem added a comment -

            The javascript regexp interpretation is actually correct. It checks for the pattern matched within the input value, not starting with.

            If you want it to start with, change the pattern to "^[a-z].*"

            RichAutocompleteBean.java patch

            --- application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichAutocompleteBean.java	(revision 22827)
            +++ application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichAutocompleteBean.java	(working copy)
            @@ -170,7 +170,7 @@
                     this.value1 = value1;
                 }
             
            -    @Pattern(regexp = "[a-z].*")
            +    @Pattern(regexp = "^[a-z].*")
                 public String getValue2() {
                     return value2;
                 }
            

            Show
            bleathem Brian Leathem added a comment - The javascript regexp interpretation is actually correct. It checks for the pattern matched within the input value, not starting with. If you want it to start with, change the pattern to "^ [a-z] .*" RichAutocompleteBean.java patch --- application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichAutocompleteBean.java (revision 22827) +++ application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichAutocompleteBean.java (working copy) @@ -170,7 +170,7 @@ this.value1 = value1; } - @Pattern(regexp = "[a-z].*") + @Pattern(regexp = "^[a-z].*") public String getValue2() { return value2; }
            Hide
            bleathem Brian Leathem added a comment -

            There is still the issue that when the pattern is "[a-z].*", the server and client side behave differently. There are two solutions as I see it:

            1. Always prepend a "^" character in the javascript regex (if it isn't already present)
            2. File an upstream issue with Bean Validation

            Further discussion is required, I'll bring it up in the developer forums.

            Show
            bleathem Brian Leathem added a comment - There is still the issue that when the pattern is " [a-z] .*", the server and client side behave differently. There are two solutions as I see it: Always prepend a "^" character in the javascript regex (if it isn't already present) File an upstream issue with Bean Validation Further discussion is required, I'll bring it up in the developer forums.
            Hide
            bleathem Brian Leathem added a comment -

            Added a '^' to the beginning and a '$' to the end of the regex pattern, if they don't already exist

            Show
            bleathem Brian Leathem added a comment - Added a '^' to the beginning and a '$' to the end of the regex pattern, if they don't already exist

              People

              • Assignee:
                bleathem Brian Leathem
                Reporter:
                jpapouse Jan Papousek
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Development