Browse Source

Merge pull request #810 from csmith/master

Fix handling of special chars in passwords when using /newserver.
pull/811/head
Greg Holmes 6 years ago
parent
commit
98eda3934e
No account linked to committer's email address

+ 13
- 1
src/main/java/com/dmdirc/util/URIParser.java View File

@@ -17,8 +17,10 @@
17 17
 
18 18
 package com.dmdirc.util;
19 19
 
20
+import java.io.UnsupportedEncodingException;
20 21
 import java.net.URI;
21 22
 import java.net.URISyntaxException;
23
+import java.net.URLDecoder;
22 24
 import java.util.regex.Matcher;
23 25
 import java.util.regex.Pattern;
24 26
 
@@ -83,7 +85,17 @@ public class URIParser {
83 85
         if (!authorityMatcher.matches()) {
84 86
             throw new InvalidURIException("Invalid address specified");
85 87
         }
86
-        userInfo = authorityMatcher.group("auth");
88
+
89
+        try {
90
+            // User info may contain special characters. When we pass individual parts to
91
+            // the URI constructor below, it encodes any characters not allowed in the user
92
+            // info. To avoid doubly-encoding them we need to decode here...
93
+            String auth = authorityMatcher.group("auth");
94
+            userInfo = auth == null ? null : URLDecoder.decode(auth, "UTF-8");
95
+        } catch (UnsupportedEncodingException ex) {
96
+            throw new InvalidURIException("Unable to create user info", ex);
97
+        }
98
+
87 99
         host = authorityMatcher.group("host");
88 100
         if (authorityMatcher.group("secure") != null && scheme.charAt(scheme.length() - 1) != 's') {
89 101
             scheme += "s";

+ 3
- 1
src/test/java/com/dmdirc/util/URIParserURIParameterizedTest.java View File

@@ -55,7 +55,9 @@ public class URIParserURIParameterizedTest {
55 55
             {"irc://irc.test.com:+6667", "ircs://irc.test.com:6667"},
56 56
             {"ircs://irc.test.com:+6667", "ircs://irc.test.com:6667"},
57 57
             {"ircs://irc.test.com:+6667", "ircs://irc.test.com:6667"},
58
-            {"ircs://username@irc.test.com:+6667", "ircs://username@irc.test.com:6667"},});
58
+            {"ircs://username@irc.test.com:+6667", "ircs://username@irc.test.com:6667"},
59
+            {"ircs://username:password%2Fnetwork@irc.test.com:+6667", "ircs://username:password%2Fnetwork@irc.test.com:6667"},
60
+        });
59 61
     }
60 62
 
61 63
 }

Loading…
Cancel
Save