File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
src/main/java/org/gitlab4j/api/utils Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments