Browse Source

Fix handling of special chars in passwords when using /newserver.

Because of the weird string->URI parts->URI conversion we do,
we have to manually decode special entities when converting
them into URI parts. (Otherwise the URI constructor encodes
them a second time)
pull/810/head
Chris Smith 6 years ago
parent
commit
515a3ddf4c
1 changed files with 12 additions and 1 deletions
  1. 12
    1
      src/main/java/com/dmdirc/util/URIParser.java

+ 12
- 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,16 @@ 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
+            userInfo = URLDecoder.decode(authorityMatcher.group("auth"), "UTF-8");
94
+        } catch (UnsupportedEncodingException ex) {
95
+            throw new InvalidURIException("Unable to create user info", ex);
96
+        }
97
+
87 98
         host = authorityMatcher.group("host");
88 99
         if (authorityMatcher.group("secure") != null && scheme.charAt(scheme.length() - 1) != 's') {
89 100
             scheme += "s";

Loading…
Cancel
Save