Package com.atlassian.adf.util
Class UrlUtil
- java.lang.Object
-
- com.atlassian.adf.util.UrlUtil
-
@Internal public class UrlUtil extends Object
Utility class for working with URLs in a way that helps keep them from breaking either Java or JavaScript code. The class originally derived from frontend code ineditor-wikimarkup-transformer/src/parser/utils/url.tsand andadf-schema/src/utils/url.ts, but has grown into something that is mostly unrelated to them, now.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringescapeSpecialChars(String url)Sanitizes a URL for maximum compatibility between Java and Javascript.static booleanisSafeUrl(String url)static StringvalidateUrl(String url, String propertyName)static StringvalidateUrl(String url, String propertyName, boolean allowEmptyPath)
-
-
-
Method Detail
-
escapeSpecialChars
public static String escapeSpecialChars(String url)
Sanitizes a URL for maximum compatibility between Java and Javascript.In particular, the URI class in Java is stricter about which characters are permitted in a URL than the JavaScript URL class is. For example, it will not permit a raw space or caret (^) character in the URL, even in segments like the query where Javascript's
new URL(url).hrefwould not bother to escape them. This performs those escapes that are required for correct parsing while leaving everything else as-is.- Parameters:
url- the original URL- Returns:
- the cleaned URL, which is hopefully suitable for parsing
- See Also:
- RFC 3986, Section 2
-
isSafeUrl
public static boolean isSafeUrl(String url)
-
validateUrl
public static String validateUrl(String url, String propertyName, boolean allowEmptyPath)
-
-