This is an automated email from the ASF dual-hosted git repository.
robbie pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/main by this push:
new 33d064df1a ARTEMIS-4926 throw checked URISyntaxException on bad URL
33d064df1a is described below
commit 33d064df1a06709f0a01e915a835280464457846
Author: Justin Bertram <[email protected]>
AuthorDate: Wed Jan 15 14:41:36 2025 -0600
ARTEMIS-4926 throw checked URISyntaxException on bad URL
---
.../activemq/artemis/utils/uri/URISupport.java | 10 +++-
.../activemq/artemis/utils/uri/URISupportTest.java | 68 ++++++++++++++++++++++
2 files changed, 76 insertions(+), 2 deletions(-)
diff --git
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URISupport.java
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URISupport.java
index 53ed8ab4ff..2d5f7b1b9a 100644
---
a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URISupport.java
+++
b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URISupport.java
@@ -156,7 +156,7 @@ public class URISupport {
/**
* Given a URI parse and extract any URI query options and return them as a
Key / Value mapping.
*
- * This method differs from the {@link parseQuery} method in that it
handles composite URI types and
+ * This method differs from the {@link URISupport#parseQuery(String)}
method in that it handles composite URI types and
* will extract the URI options from the outermost composite URI.
*
* @param uri The URI whose query should be extracted and processed.
@@ -165,7 +165,13 @@ public class URISupport {
*/
public static Map<String, String> parseParameters(URI uri) throws
URISyntaxException {
if (!isCompositeURI(uri)) {
- return uri.getQuery() == null ? emptyMap() :
parseQuery(stripPrefix(uri.getQuery(), "?"));
+ try {
+ return uri.getQuery() == null ? emptyMap() :
parseQuery(stripPrefix(uri.getQuery(), "?"));
+ } catch (IllegalArgumentException e) {
+ URISyntaxException uriSyntaxException = new
URISyntaxException(uri.toString(), e.getMessage());
+ uriSyntaxException.initCause(e);
+ throw uriSyntaxException;
+ }
} else {
CompositeData data = URISupport.parseComposite(uri);
Map<String, String> parameters = new HashMap<>();
diff --git
a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/uri/URISupportTest.java
b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/uri/URISupportTest.java
new file mode 100644
index 0000000000..512fa8bada
--- /dev/null
+++
b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/uri/URISupportTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.activemq.artemis.utils.uri;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.fail;
+
+public class URISupportTest {
+
+ @Test
+ public void testBadParameterValues() throws Exception {
+ try {
+ URISupport.parseParameters(new
URI("tcp://127.0.0.1:61616?foo=bar&KK%258K="));
+ fail();
+ } catch (URISyntaxException e) {
+ // expected
+ }
+
+ try {
+ URISupport.parseParameters(new
URI("tcp://127.0.0.1:61616?bar=baz&,KK%25İK="));
+ fail();
+ } catch (URISyntaxException e) {
+ // expected
+ }
+
+ try {
+ URISupport.parseParameters(new
URI("tcp://127.0.0.1:61616?KK%25-8K=&bee=boo"));
+ fail();
+ } catch (URISyntaxException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testBadParameterNames() throws Exception {
+ try {
+ URISupport.parseParameters(new
URI("tcp://127.0.0.1:61616?foo=bar&K8K=K%258K="));
+ fail();
+ } catch (URISyntaxException e) {
+ // expected
+ }
+
+ try {
+ URISupport.parseParameters(new
URI("tcp://127.0.0.1:61616?bar=baz&KKKÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆ=%25#¿8K="));
+ fail();
+ } catch (URISyntaxException e) {
+ // expected
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact