Skip to content

Commit 62e5523

Browse files
author
TheSnoozer
committed
#519: fix an issue where special characters in the git URL simply yield: Illegal character in authority
1 parent abae657 commit 62e5523

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

core/src/main/java/pl/project13/core/GitDataProvider.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
import javax.annotation.Nonnull;
2727
import java.net.URI;
28+
import java.net.URLEncoder;
29+
import java.nio.charset.StandardCharsets;
2830
import java.util.*;
2931
import java.text.SimpleDateFormat;
3032
import java.util.concurrent.atomic.AtomicBoolean;
@@ -299,6 +301,15 @@ protected String stripCredentialsFromOriginUrl(String gitRemoteString) throws Gi
299301
}
300302
// At this point, we should have a properly formatted URL
301303
try {
304+
305+
for (String s: Arrays.asList(
306+
// escape all 'delims' characters in a URI as per https://www.ietf.org/rfc/rfc2396.txt
307+
"<", ">", "#", "%", "\"",
308+
// escape all 'unwise' characters in a URI as per https://www.ietf.org/rfc/rfc2396.txt
309+
"{", "}", "|", "\\", "^", "[", "]", "`")) {
310+
gitRemoteString = gitRemoteString.replaceAll(
311+
Pattern.quote(s), URLEncoder.encode(s, StandardCharsets.UTF_8.toString()));
312+
}
302313
URI original = new URI(gitRemoteString);
303314
String userInfoString = original.getUserInfo();
304315
if (null == userInfoString) {
@@ -329,4 +340,4 @@ protected String stripCredentialsFromOriginUrl(String gitRemoteString) throws Gi
329340
return "";
330341
}
331342
}
332-
}
343+
}

maven/src/test/java/pl/project13/core/UriUserInfoRemoverTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ public static Collection<Object[]> parameters() {
5252
{ "file:///path/to/repo.git/", "file:///path/to/repo.git/"},
5353
{ "file:///C:\\Users\\test\\example", "file:///C:\\Users\\test\\example"},
5454
{ "file://C:\\Users\\test\\example", "file://C:\\Users\\test\\example" },
55+
// use of 'reserved' characters as https://www.ietf.org/rfc/rfc2396.txt
56+
// note: left out '/' since we can't simply escape it
57+
{ "https://user:A;?:@&=+$,Z@example.com:8888", "https://user@example.com:8888" },
58+
// use of 'unreserved' characters as https://www.ietf.org/rfc/rfc2396.txt
59+
{ "https://user:A-_.!~*'()Z@example.com:8888", "https://user@example.com:8888" },
60+
// use of 'delims' characters as https://www.ietf.org/rfc/rfc2396.txt
61+
{ "https://user:A<>#%\"Z@example.com:8888", "https://user@example.com:8888" },
62+
// use of 'unwise' characters as https://www.ietf.org/rfc/rfc2396.txt
63+
{ "https://user:A{}|\\^[]`Z@example.com:8888", "https://user@example.com:8888" },
5564
};
5665
return Arrays.asList(data);
5766
}

0 commit comments

Comments
 (0)