cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7015] Capture invalid escapes and throw IllegalArgumentException, patch from iammichaelgrant applied, This close #196
Date Wed, 16 Nov 2016 14:14:31 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 13fa5dc1f -> 3f66a2b07


[CXF-7015] Capture invalid escapes and throw IllegalArgumentException, patch from iammichaelgrant
applied, This close #196


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/3f66a2b0
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/3f66a2b0
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/3f66a2b0

Branch: refs/heads/3.1.x-fixes
Commit: 3f66a2b0797e3eb8a1e1e7c29b98fa603ceebf0a
Parents: 13fa5dc
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Wed Nov 16 15:10:26 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Wed Nov 16 15:14:06 2016 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/cxf/common/util/UrlUtils.java    |  8 +++++---
 .../java/org/apache/cxf/common/util/UrlUtilsTest.java     | 10 ++++++++++
 2 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/3f66a2b0/core/src/main/java/org/apache/cxf/common/util/UrlUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/common/util/UrlUtils.java b/core/src/main/java/org/apache/cxf/common/util/UrlUtils.java
index 628c092..3b7dd23 100644
--- a/core/src/main/java/org/apache/cxf/common/util/UrlUtils.java
+++ b/core/src/main/java/org/apache/cxf/common/util/UrlUtils.java
@@ -21,6 +21,7 @@ package org.apache.cxf.common.util;
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
+import java.nio.BufferUnderflowException;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
@@ -96,8 +97,9 @@ public final class UrlUtils {
                         final int u = digit16((byte) in.get());
                         final int l = digit16((byte) in.get());
                         out.put((byte) ((u << 4) + l));
-                    } catch (final ArrayIndexOutOfBoundsException e) {
-                        throw new RuntimeException("Invalid URL encoding: ", e);
+                    } catch (final BufferUnderflowException e) {
+                        throw new IllegalArgumentException(
+                                "Invalid URL encoding: Incomplete trailing escape (%) pattern");
                     }
                 } else {
                     out.put((byte) b);
@@ -113,7 +115,7 @@ public final class UrlUtils {
     private static int digit16(final byte b) {
         final int i = Character.digit((char) b, RADIX);
         if (i == -1) {
-            throw new RuntimeException("Invalid URL encoding: not a valid digit (radix "
+ RADIX + "): " + b);
+            throw new IllegalArgumentException("Invalid URL encoding: not a valid digit (radix
" + RADIX + "): " + b);
         }
         return i;
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/3f66a2b0/core/src/test/java/org/apache/cxf/common/util/UrlUtilsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/cxf/common/util/UrlUtilsTest.java b/core/src/test/java/org/apache/cxf/common/util/UrlUtilsTest.java
index 3989e9f..b0e25b7 100644
--- a/core/src/test/java/org/apache/cxf/common/util/UrlUtilsTest.java
+++ b/core/src/test/java/org/apache/cxf/common/util/UrlUtilsTest.java
@@ -41,6 +41,16 @@ public class UrlUtilsTest extends Assert {
     public void testUrlDecodeReserved() {
         assertEquals("!$&'()*,;=", UrlUtils.urlDecode("!$&'()*,;="));
     }
+
+    @Test (expected = IllegalArgumentException.class)
+    public void testUrlDecodeIncompleteEscape() {
+        UrlUtils.urlDecode("%2");
+    }
+
+    @Test (expected = IllegalArgumentException.class)
+    public void testUrlDecodeInvalidEscape() {
+        UrlUtils.urlDecode("%2$");
+    }
     
     @Test
     public void testPathDecode() {


Mime
View raw message