Skip to content

Commit

Permalink
Merge pull request apache#1808, fix URL parsing problem when user fil…
Browse files Browse the repository at this point in the history
…ed contains '@' characters.

Fixed apache#1470
  • Loading branch information
leiwei2094 authored and chickenlj committed May 17, 2018
1 parent c784fa0 commit 8d11dba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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(":");
Expand Down
15 changes: 15 additions & 0 deletions dubbo-common/src/test/java/com/alibaba/dubbo/common/URLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}

0 comments on commit 8d11dba

Please sign in to comment.