chickenlj closed pull request #1808: [Dubbo-1470] Extract username and password 
correctly when them contains "@" character #1470
URL: https://github.com/apache/incubator-dubbo/pull/1808
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/dubbo-common/src/main/java/com/alibaba/dubbo/common/URL.java 
b/dubbo-common/src/main/java/com/alibaba/dubbo/common/URL.java
index f96946db75..f8a111967b 100644
--- a/dubbo-common/src/main/java/com/alibaba/dubbo/common/URL.java
+++ b/dubbo-common/src/main/java/com/alibaba/dubbo/common/URL.java
@@ -224,7 +224,7 @@ public static URL valueOf(String url) {
             path = url.substring(i + 1);
             url = url.substring(0, i);
         }
-        i = url.indexOf("@");
+        i = url.lastIndexOf("@");
         if (i >= 0) {
             username = url.substring(0, i);
             int j = username.indexOf(":");
diff --git a/dubbo-common/src/test/java/com/alibaba/dubbo/common/URLTest.java 
b/dubbo-common/src/test/java/com/alibaba/dubbo/common/URLTest.java
index a670c3c405..0a19b7abb0 100644
--- a/dubbo-common/src/test/java/com/alibaba/dubbo/common/URLTest.java
+++ b/dubbo-common/src/test/java/com/alibaba/dubbo/common/URLTest.java
@@ -637,4 +637,19 @@ public void testAddParameters() throws Exception {
         parameters.put("version", null);
         url.addParameters(parameters);
     }
+
+    @Test
+    public void testUserNamePasswordContainsAt(){
+        // Test username or password contains "@"
+        URL url = 
URL.valueOf("ad@min:hello@1234@10.20.130.230:20880/context/path?version=1.0.0&application=morgan");
+        assertNull(url.getProtocol());
+        assertEquals("ad@min", url.getUsername());
+        assertEquals("hello@1234", url.getPassword());
+        assertEquals("10.20.130.230", url.getHost());
+        assertEquals(20880, url.getPort());
+        assertEquals("context/path", url.getPath());
+        assertEquals(2, url.getParameters().size());
+        assertEquals("1.0.0", url.getParameter("version"));
+        assertEquals("morgan", url.getParameter("application"));
+    }
 }
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org
For additional commands, e-mail: notifications-h...@dubbo.apache.org

Reply via email to