ソースを参照

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年前
コミット
515a3ddf4c
1個のファイルの変更12行の追加1行の削除
  1. 12
    1
      src/main/java/com/dmdirc/util/URIParser.java

+ 12
- 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
+            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
         host = authorityMatcher.group("host");
98
         host = authorityMatcher.group("host");
88
         if (authorityMatcher.group("secure") != null && scheme.charAt(scheme.length() - 1) != 's') {
99
         if (authorityMatcher.group("secure") != null && scheme.charAt(scheme.length() - 1) != 's') {
89
             scheme += "s";
100
             scheme += "s";

読み込み中…
キャンセル
保存