Author: awiner
Date: Tue Jun 9 18:10:43 2009
New Revision: 783086
URL: http://svn.apache.org/viewvc?rev=783086&view=rev
Log:
Don't NPE if functions are passed null - just return null.
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/expressions/OpensocialFunctions.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/expressions/OpensocialFunctionsTest.java
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/expressions/OpensocialFunctions.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/expressions/OpensocialFunctions.java?rev=783086&r1=783085&r2=783086&view=diff
==============================================================================
---
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/expressions/OpensocialFunctions.java
(original)
+++
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/expressions/OpensocialFunctions.java
Tue Jun 9 18:10:43 2009
@@ -61,6 +61,10 @@
*/
@Functions.Expose(prefix = "osx", names = {"decodeBase64"})
public static String decodeBase64(String text) {
+ if (text == null) {
+ return null;
+ }
+
try {
// TODO: allow a charset to be passed in?
return new String(Base64.decodeBase64(text.getBytes("UTF-8")),
@@ -76,6 +80,10 @@
*/
@Functions.Expose(prefix = "osx", names = {"urlEncode"})
public static String formEncode(String text) {
+ if (text == null) {
+ return null;
+ }
+
return Utf8UrlCoder.encode(text);
}
@@ -86,6 +94,10 @@
*/
@Functions.Expose(prefix = "osx", names = {"urlDecode"})
public static String formDecode(String text) {
+ if (text == null) {
+ return null;
+ }
+
return Utf8UrlCoder.decode(text);
}
}
Modified:
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/expressions/OpensocialFunctionsTest.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/expressions/OpensocialFunctionsTest.java?rev=783086&r1=783085&r2=783086&view=diff
==============================================================================
---
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/expressions/OpensocialFunctionsTest.java
(original)
+++
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/expressions/OpensocialFunctionsTest.java
Tue Jun 9 18:10:43 2009
@@ -79,4 +79,28 @@
expressions.parse("${osx:urlDecode(encoded)}", String.class);
assertEquals("He He", testUrlDecode.getValue(context));
}
+
+ public void testParseJsonNull() throws Exception {
+ ValueExpression testUrlEncode =
+ expressions.parse("${osx:parseJson(null)}", String.class);
+ assertEquals("", testUrlEncode.getValue(context));
+ }
+
+ public void testDecodeBase64Null() throws Exception {
+ ValueExpression testUrlEncode =
+ expressions.parse("${osx:decodeBase64(null)}", String.class);
+ assertEquals("", testUrlEncode.getValue(context));
+ }
+
+ public void testUrlEncodeNull() throws Exception {
+ ValueExpression testUrlEncode =
+ expressions.parse("${osx:urlEncode(null)}", String.class);
+ assertEquals("", testUrlEncode.getValue(context));
+ }
+
+ public void testUrlDecodeNull() throws Exception {
+ ValueExpression testUrlDecode =
+ expressions.parse("${osx:urlDecode(null)}", String.class);
+ assertEquals("", testUrlDecode.getValue(context));
+ }
}