struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [1/2] struts git commit: WW-4810 Fixes issue with passing an empty locale on JDK8
Date Thu, 06 Jul 2017 05:56:48 GMT
Repository: struts
Updated Branches:
  refs/heads/master f84255783 -> 666271ccd


WW-4810 Fixes issue with passing an empty locale on JDK8


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/67536bf2
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/67536bf2
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/67536bf2

Branch: refs/heads/master
Commit: 67536bf2d2440256c9c46f9a6128cff0875629d6
Parents: f842557
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Thu Jul 6 07:46:32 2017 +0200
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Thu Jul 6 07:46:32 2017 +0200

----------------------------------------------------------------------
 .../xwork2/DefaultLocaleProvider.java           |  8 ++++----
 .../interceptor/I18nInterceptorTest.java        | 21 +++++++++++++++++++-
 2 files changed, 24 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/67536bf2/core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java b/core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java
index bdb6d7c..9eea2b3 100644
--- a/core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java
+++ b/core/src/main/java/com/opensymphony/xwork2/DefaultLocaleProvider.java
@@ -16,11 +16,11 @@
 package com.opensymphony.xwork2;
 
 import org.apache.commons.lang3.LocaleUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.message.ParameterizedMessage;
 
-import java.util.Arrays;
 import java.util.Locale;
 
 /**
@@ -45,15 +45,15 @@ public class DefaultLocaleProvider implements LocaleProvider {
     public boolean isValidLocaleString(String localeStr) {
         Locale locale = null;
         try {
-            locale = LocaleUtils.toLocale(localeStr);
+            locale = LocaleUtils.toLocale(StringUtils.trimToNull(localeStr));
         } catch (IllegalArgumentException e) {
-            LOG.warn(new ParameterizedMessage("Cannot convert [{}] to proper locale", localeStr,
e));
+            LOG.warn(new ParameterizedMessage("Cannot convert [{}] to proper locale", localeStr),
e);
         }
         return isValidLocale(locale);
     }
 
     @Override
     public boolean isValidLocale(Locale locale) {
-        return locale != null && Arrays.asList(Locale.getAvailableLocales()).contains(locale);
+        return LocaleUtils.isAvailableLocale(locale);
     }
 }

http://git-wip-us.apache.org/repos/asf/struts/blob/67536bf2/core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java
index a38b8c4..42a075b1 100644
--- a/core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java
+++ b/core/src/test/java/org/apache/struts2/interceptor/I18nInterceptorTest.java
@@ -23,7 +23,6 @@ package org.apache.struts2.interceptor;
 import com.opensymphony.xwork2.Action;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionInvocation;
-import com.opensymphony.xwork2.DefaultLocaleProvider;
 import com.opensymphony.xwork2.DefaultLocaleProviderFactory;
 import com.opensymphony.xwork2.mock.MockActionInvocation;
 import com.opensymphony.xwork2.mock.MockActionProxy;
@@ -101,6 +100,26 @@ public class I18nInterceptorTest extends TestCase {
         assertEquals(denmark, session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); //
should create a locale object
     }
 
+    public void testEmptyLocale() throws Exception {
+        prepare(I18nInterceptor.DEFAULT_PARAMETER, "");
+        interceptor.intercept(mai);
+
+        assertFalse(mai.getInvocationContext().getParameters().get(I18nInterceptor.DEFAULT_PARAMETER).isDefined());
// should have been removed
+
+        assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should
be stored here
+        assertEquals(Locale.getDefault(), session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE));
// should create a locale object
+    }
+
+    public void testNotExistingLocale() throws Exception {
+        prepare(I18nInterceptor.DEFAULT_PARAMETER, "ble");
+        interceptor.intercept(mai);
+
+        assertFalse(mai.getInvocationContext().getParameters().get(I18nInterceptor.DEFAULT_PARAMETER).isDefined());
// should have been removed
+
+        assertNotNull(session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE)); // should
be stored here
+        assertEquals(Locale.getDefault(), session.get(I18nInterceptor.DEFAULT_SESSION_ATTRIBUTE));
// should create a locale object
+    }
+
     public void testWithVariant() throws Exception {
         prepare(I18nInterceptor.DEFAULT_PARAMETER, "ja_JP_JP");
         interceptor.intercept(mai);


Mime
View raw message