From b65e6dcd57532d2ed475c30b9ce6c81a139687ce Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Wed, 07 May 2014 13:42:08 -0400
Subject: [PATCH] Correct Bintray upload url for releases
---
src/main/java/com/gitblit/utils/StringUtils.java | 39 +++++++++++++++++++++++++++++++++++++--
1 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/src/main/java/com/gitblit/utils/StringUtils.java b/src/main/java/com/gitblit/utils/StringUtils.java
index e18bdc4..d7e1ea3 100644
--- a/src/main/java/com/gitblit/utils/StringUtils.java
+++ b/src/main/java/com/gitblit/utils/StringUtils.java
@@ -127,12 +127,26 @@
retStr.append("%2F");
} else if (inStr.charAt(i) == ' ') {
retStr.append("%20");
+ } else if (inStr.charAt(i) == '&') {
+ retStr.append("%26");
} else {
retStr.append(inStr.charAt(i));
}
i++;
}
return retStr.toString();
+ }
+
+ /**
+ * Flatten the list of strings into a single string with the specified
+ * separator.
+ *
+ * @param values
+ * @param separator
+ * @return flattened list
+ */
+ public static String flattenStrings(String[] values, String separator) {
+ return flattenStrings(Arrays.asList(values), separator);
}
/**
@@ -293,7 +307,7 @@
* @param bytes
* @return byte array as hex string
*/
- private static String toHex(byte[] bytes) {
+ public static String toHex(byte[] bytes) {
StringBuilder sb = new StringBuilder(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
if ((bytes[i] & 0xff) < 0x10) {
@@ -628,7 +642,7 @@
// ignore unsupported charsets
}
}
- if (value.startsWith("\uFEFF")) {
+ if (value != null && value.startsWith("\uFEFF")) {
// strip UTF-8 BOM
return value.substring(1);
}
@@ -747,4 +761,25 @@
}
return input.replace('\n',' ').replace('\r', ' ').trim();
}
+
+
+ /**
+ * Encode the username for user in an url.
+ *
+ * @param name
+ * @return the encoded name
+ */
+ public static String encodeUsername(String name) {
+ return name.replace("@", "%40").replace(" ", "%20").replace("\\", "%5C");
+ }
+
+ /**
+ * Decode a username from an encoded url.
+ *
+ * @param name
+ * @return the decoded name
+ */
+ public static String decodeUsername(String name) {
+ return name.replace("%40", "@").replace("%20", " ").replace("%5C", "\\");
+ }
}
\ No newline at end of file
--
Gitblit v1.9.1