Skip to content

Commit 09aff84

Browse files
committed
Initial commit.
1 parent 7e83c0d commit 09aff84

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.gitlab4j.api.utils;
2+
3+
import java.net.URLEncoder;
4+
5+
import org.gitlab4j.api.GitLabApiException;
6+
7+
public class UrlEncoder {
8+
9+
/**
10+
* URL encodes a String in compliance with GitLabs special differences.
11+
*
12+
* @param s the String to URL encode
13+
* @return the URL encoded strings
14+
* @throws GitLabApiException if any exception occurs
15+
*/
16+
public static String urlEncode(String s) throws GitLabApiException {
17+
18+
try {
19+
String encoded = URLEncoder.encode(s, "UTF-8");
20+
// Since the encode method encodes plus signs as %2B,
21+
// we can simply replace the encoded spaces with the correct encoding here
22+
encoded = encoded.replace("+", "%20");
23+
encoded = encoded.replace(".", "%2E");
24+
encoded = encoded.replace("-", "%2D");
25+
encoded = encoded.replace("_", "%5F");
26+
return (encoded);
27+
} catch (Exception e) {
28+
throw new GitLabApiException(e);
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)