Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4677

I18N Interceptor automatically validates Locale

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5
    • Fix Version/s: 2.5.5
    • Component/s: Core Interceptors
    • Labels:
      None
    • Environment:

      2.5.1 running on Java 8, RHEL Linux 6/7

      Description

      There is an annoying issue with the I18N Interceptor, which now validates locales against the list of default available locales in this bit of code:

      if (locale != null && Arrays.asList(Locale.getAvailableLocales()).contains(locale)) {
          locale = Locale.getDefault();
      }
      

      The problem is I have a web app for refugees and not all the languages are in the available locales array. This must be relatively new as it worked in the old version 2.x ish.

      Ideally it would be great if we could add a parameter (or constant) to bi-pass the validation.

      For example a tag in the struts.xml file:

      <interceptor-ref name="I18nInterceptor">
        <param name="validation">
           false
        </param>
      </interceptor-ref>
      

      and then access it in the interceptor to override default behaviour.

        Activity

        Hide
        hudson Hudson added a comment -

        SUCCESS: Integrated in Jenkins build Struts-JDK7-master #529 (See https://builds.apache.org/job/Struts-JDK7-master/529/)
        WW-4677 Ignores locale set to null (lukaszlenart: rev 6916f47c97ae06c7d0a1dedba38cefcd6566ee36)

        • (edit) core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java
        • (edit) core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java
        Show
        hudson Hudson added a comment - SUCCESS: Integrated in Jenkins build Struts-JDK7-master #529 (See https://builds.apache.org/job/Struts-JDK7-master/529/ ) WW-4677 Ignores locale set to null (lukaszlenart: rev 6916f47c97ae06c7d0a1dedba38cefcd6566ee36) (edit) core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java (edit) core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 6916f47c97ae06c7d0a1dedba38cefcd6566ee36 in struts's branch refs/heads/master from Lukasz Lenart
        [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=6916f47 ]

        WW-4677 Ignores locale set to null

        Show
        jira-bot ASF subversion and git services added a comment - Commit 6916f47c97ae06c7d0a1dedba38cefcd6566ee36 in struts's branch refs/heads/master from Lukasz Lenart [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=6916f47 ] WW-4677 Ignores locale set to null
        Hide
        hudson Hudson added a comment -

        SUCCESS: Integrated in Jenkins build Struts-JDK7-master #527 (See https://builds.apache.org/job/Struts-JDK7-master/527/)
        WW-4677 Exyends LocaleProvider to be used to validate Locale (lukaszlenart: rev ea92e95461386f1ddfda37bb09ec170b8e306ae7)

        • (edit) core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java
        • (edit) core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java
        • (edit) core/src/test/java/com/opensymphony/xwork2/validator/StringLengthFieldValidatorTest.java
        • (edit) core/src/main/java/com/opensymphony/xwork2/LocaleProvider.java
        • (edit) core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java
        • (edit) core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java
        • (edit) core/src/test/java/com/opensymphony/xwork2/validator/VisitorFieldValidatorTest.java
        • (edit) core/src/test/java/com/opensymphony/xwork2/CompositeTextProviderTest.java
        • (edit) core/src/test/java/com/opensymphony/xwork2/TextProviderSupportTest.java
        • (edit) core/src/test/java/org/apache/struts2/views/jsp/TextTagTest.java
        • (edit) core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java
        • (edit) core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java
        • (edit) core/src/test/java/org/apache/struts2/views/jsp/ui/OptGroupTest.java
        • (edit) core/src/main/java/com/opensymphony/xwork2/ActionSupport.java
        • (edit) core/src/test/java/com/opensymphony/xwork2/validator/SimpleActionValidationTest.java
        • (edit) core/src/test/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverterTest.java
        • (edit) core/src/test/java/com/opensymphony/xwork2/util/LocalizedTextUtilTest.java
        • (edit) core/src/test/java/com/opensymphony/xwork2/conversion/impl/XWorkConverterTest.java
        • (edit) core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java
        Show
        hudson Hudson added a comment - SUCCESS: Integrated in Jenkins build Struts-JDK7-master #527 (See https://builds.apache.org/job/Struts-JDK7-master/527/ ) WW-4677 Exyends LocaleProvider to be used to validate Locale (lukaszlenart: rev ea92e95461386f1ddfda37bb09ec170b8e306ae7) (edit) core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java (edit) core/src/main/java/com/opensymphony/xwork2/validator/DelegatingValidatorContext.java (edit) core/src/test/java/com/opensymphony/xwork2/validator/StringLengthFieldValidatorTest.java (edit) core/src/main/java/com/opensymphony/xwork2/LocaleProvider.java (edit) core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java (edit) core/src/main/java/org/apache/struts2/interceptor/I18nInterceptor.java (edit) core/src/test/java/com/opensymphony/xwork2/validator/VisitorFieldValidatorTest.java (edit) core/src/test/java/com/opensymphony/xwork2/CompositeTextProviderTest.java (edit) core/src/test/java/com/opensymphony/xwork2/TextProviderSupportTest.java (edit) core/src/test/java/org/apache/struts2/views/jsp/TextTagTest.java (edit) core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java (edit) core/src/test/java/org/apache/struts2/interceptor/FileUploadInterceptorTest.java (edit) core/src/test/java/org/apache/struts2/views/jsp/ui/OptGroupTest.java (edit) core/src/main/java/com/opensymphony/xwork2/ActionSupport.java (edit) core/src/test/java/com/opensymphony/xwork2/validator/SimpleActionValidationTest.java (edit) core/src/test/java/com/opensymphony/xwork2/conversion/impl/AnnotationXWorkConverterTest.java (edit) core/src/test/java/com/opensymphony/xwork2/util/LocalizedTextUtilTest.java (edit) core/src/test/java/com/opensymphony/xwork2/conversion/impl/XWorkConverterTest.java (edit) core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit ea92e95461386f1ddfda37bb09ec170b8e306ae7 in struts's branch refs/heads/master from Lukasz Lenart
        [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=ea92e95 ]

        WW-4677 Exyends LocaleProvider to be used to validate Locale

        Show
        jira-bot ASF subversion and git services added a comment - Commit ea92e95461386f1ddfda37bb09ec170b8e306ae7 in struts's branch refs/heads/master from Lukasz Lenart [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=ea92e95 ] WW-4677 Exyends LocaleProvider to be used to validate Locale
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        I went a be different way and extended LocaleProvider to be used as a validator in context of Locale, now you can implement your own versions to be used with the I18NInterceptor and it will be consistent over the whole framework

        Show
        lukaszlenart Lukasz Lenart added a comment - I went a be different way and extended LocaleProvider to be used as a validator in context of Locale , now you can implement your own versions to be used with the I18NInterceptor and it will be consistent over the whole framework
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        We can do both things, strict validation against getAvailableLocales(), a regex validation and no validation. It can be global setting (via Struts constant) or per interceptor stack (which is more flexible)

        Show
        lukaszlenart Lukasz Lenart added a comment - We can do both things, strict validation against getAvailableLocales() , a regex validation and no validation. It can be global setting (via Struts constant) or per interceptor stack (which is more flexible)
        Hide
        zoran Zoran Avtarovski added a comment -

        Thanks Lukasz,

        I see the issue nut in reality, it's only an issue if you display the locale. Which can be accommodated by setting the default behaviour to validate.

        We could add some simple validation to ensure no special characters are included in the request. All I did was run a simple regex to remove potentially dangerous characters :

        String result = localeParameter.replaceAll("[%{}+.^:,]","");
        

        I'll leave it up to you guys. Just let me know if you'd like me to submit a patch.

        I looked at it a little further and I think using a struts constant is the least intrusive way.

        Z.

        Show
        zoran Zoran Avtarovski added a comment - Thanks Lukasz, I see the issue nut in reality, it's only an issue if you display the locale. Which can be accommodated by setting the default behaviour to validate. We could add some simple validation to ensure no special characters are included in the request. All I did was run a simple regex to remove potentially dangerous characters : String result = localeParameter.replaceAll( "[%{}+.^:,]" ,""); I'll leave it up to you guys. Just let me know if you'd like me to submit a patch. I looked at it a little further and I think using a struts constant is the least intrusive way. Z.
        Hide
        lukaszlenart Lukasz Lenart added a comment -
        Show
        lukaszlenart Lukasz Lenart added a comment - It was due to http://struts.apache.org/docs/s2-030.html

          People

          • Assignee:
            Unassigned
            Reporter:
            zoran Zoran Avtarovski
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development