Переглянути джерело

Merge pull request #810 from csmith/master

Fix handling of special chars in passwords when using /newserver.
pull/811/head
Greg Holmes 6 роки тому
джерело
коміт
98eda3934e
Аккаунт користувача з таким Email не знайдено

+ 13
- 1
src/main/java/com/dmdirc/util/URIParser.java Переглянути файл

17
 
17
 
18
 package com.dmdirc.util;
18
 package com.dmdirc.util;
19
 
19
 
20
+import java.io.UnsupportedEncodingException;
20
 import java.net.URI;
21
 import java.net.URI;
21
 import java.net.URISyntaxException;
22
 import java.net.URISyntaxException;
23
+import java.net.URLDecoder;
22
 import java.util.regex.Matcher;
24
 import java.util.regex.Matcher;
23
 import java.util.regex.Pattern;
25
 import java.util.regex.Pattern;
24
 
26
 
83
         if (!authorityMatcher.matches()) {
85
         if (!authorityMatcher.matches()) {
84
             throw new InvalidURIException("Invalid address specified");
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
         host = authorityMatcher.group("host");
99
         host = authorityMatcher.group("host");
88
         if (authorityMatcher.group("secure") != null && scheme.charAt(scheme.length() - 1) != 's') {
100
         if (authorityMatcher.group("secure") != null && scheme.charAt(scheme.length() - 1) != 's') {
89
             scheme += "s";
101
             scheme += "s";

+ 3
- 1
src/test/java/com/dmdirc/util/URIParserURIParameterizedTest.java Переглянути файл

55
             {"irc://irc.test.com:+6667", "ircs://irc.test.com:6667"},
55
             {"irc://irc.test.com:+6667", "ircs://irc.test.com:6667"},
56
             {"ircs://irc.test.com:+6667", "ircs://irc.test.com:6667"},
56
             {"ircs://irc.test.com:+6667", "ircs://irc.test.com:6667"},
57
             {"ircs://irc.test.com:+6667", "ircs://irc.test.com:6667"},
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
 }

Завантаження…
Відмінити
Зберегти