mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-28 14:57:12 +00:00
Bug 2909: Added '+' to the list of chars that are being encoded
This commit is contained in:
1 parent
d5fc40b70a
commit
526803ab78
1 file changed
+26
-26
@@ -1,26 +1,26 @@
|
||||
package com.sap.sse.gwt.client;
|
||||
|
||||
import com.google.gwt.http.client.URL;
|
||||
|
||||
/**
|
||||
* A very basic URL encoder that also works in a GWT environment where <code>java.net.URLEncoder</code> is not available.
|
||||
* It is based on {@link URL#encode(String)} and adds encoding for the backslash (\) character.
|
||||
*
|
||||
* @author Axel Uhl (D043530)
|
||||
*
|
||||
*/
|
||||
public class URLEncoder {
|
||||
|
||||
private URLEncoder() { }
|
||||
|
||||
private final static char[] charsToReplace = { '\'', '(', ')', '"', '[', ']', '{', '}', '<', '>', '|' };
|
||||
|
||||
public static String encode(String url) {
|
||||
String nearlyEncoded = URL.encode(url);
|
||||
for (char c : charsToReplace) {
|
||||
nearlyEncoded = nearlyEncoded.replaceAll("\\" + Character.toString(c), "%" + Integer.toHexString(c));
|
||||
}
|
||||
return nearlyEncoded;
|
||||
}
|
||||
|
||||
}
|
||||
package com.sap.sse.gwt.client;
|
||||
|
||||
import com.google.gwt.http.client.URL;
|
||||
|
||||
/**
|
||||
* A very basic URL encoder that also works in a GWT environment where <code>java.net.URLEncoder</code> is not available.
|
||||
* It is based on {@link URL#encode(String)} and adds encoding for the backslash (\) character.
|
||||
*
|
||||
* @author Axel Uhl (D043530)
|
||||
*
|
||||
*/
|
||||
public class URLEncoder {
|
||||
|
||||
private URLEncoder() { }
|
||||
|
||||
private final static char[] charsToReplace = { '\'', '(', ')', '"', '[', ']', '{', '}', '<', '>', '|', '+' };
|
||||
|
||||
public static String encode(String url) {
|
||||
String nearlyEncoded = URL.encode(url);
|
||||
for (char c : charsToReplace) {
|
||||
nearlyEncoded = nearlyEncoded.replaceAll("\\" + Character.toString(c), "%" + Integer.toHexString(c));
|
||||
}
|
||||
return nearlyEncoded;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user