Repository: olingo-odata2 Updated Branches: refs/heads/master 345b33dde -> f10670a8a
[OLINGO-591] Empty query parameter string fixed Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/f10670a8 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/f10670a8 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/f10670a8 Branch: refs/heads/master Commit: f10670a8ac9521b274656f5f46ddd81651c2d25d Parents: 345b33d Author: Michael Bolz <[email protected]> Authored: Tue Mar 24 13:53:14 2015 +0100 Committer: Michael Bolz <[email protected]> Committed: Tue Mar 24 13:57:22 2015 +0100 ---------------------------------------------------------------------- .../olingo/odata2/core/servlet/RestUtil.java | 4 +- .../odata2/core/servlet/RestUtilTest.java | 59 ++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f10670a8/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java index ff49077..65aaf06 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java @@ -90,7 +90,7 @@ public class RestUtil { */ public static Map<String, String> extractQueryParameters(final String queryString) { Map<String, String> queryParametersMap = new HashMap<String, String>(); - if (queryString != null) { + if (queryString != null && queryString.length() > 0) { // At first the queryString will be decoded. List<String> queryParameters = Arrays.asList(queryString.split("\\&")); for (String param : queryParameters) { @@ -110,7 +110,7 @@ public class RestUtil { public static Map<String, List<String>> extractAllQueryParameters(final String queryString) { Map<String, List<String>> allQueryParameterMap = new HashMap<String, List<String>>(); - if (queryString != null) { + if (queryString != null && queryString.length() > 0) { // At first the queryString will be decoded. List<String> queryParameters = Arrays.asList(queryString.split("\\&")); for (String param : queryParameters) { http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f10670a8/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/RestUtilTest.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/RestUtilTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/RestUtilTest.java new file mode 100644 index 0000000..233cba6 --- /dev/null +++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/RestUtilTest.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + ******************************************************************************/ +package org.apache.olingo.odata2.core.servlet; + +import junit.framework.Assert; +import org.junit.Test; + +import java.util.List; +import java.util.Map; + +public class RestUtilTest { + + @Test + public void testExtractQueryParameters() throws Exception { + Map<String, String> result = RestUtil.extractQueryParameters("some=value"); + Assert.assertEquals("value", result.get("some")); + + result = RestUtil.extractQueryParameters("some=value&another=v"); + Assert.assertEquals("value", result.get("some")); + Assert.assertEquals("v", result.get("another")); + + result = RestUtil.extractQueryParameters(""); + Assert.assertTrue(result.isEmpty()); + } + + @Test + public void testExtractAllQueryParameters() throws Exception { + Map<String, List<String>> result = RestUtil.extractAllQueryParameters("some=value"); + Assert.assertEquals("value", result.get("some").get(0)); + + result = RestUtil.extractAllQueryParameters("some=value&another=v"); + Assert.assertEquals("value", result.get("some").get(0)); + Assert.assertEquals("v", result.get("another").get(0)); + + result = RestUtil.extractAllQueryParameters(""); + Assert.assertTrue(result.isEmpty()); + + result = RestUtil.extractAllQueryParameters("some=v1&another=v&some=v2"); + Assert.assertEquals("v1", result.get("some").get(0)); + Assert.assertEquals("v2", result.get("some").get(1)); + Assert.assertEquals("v", result.get("another").get(0)); + } +} \ No newline at end of file
