Class 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 in editor-wikimarkup-transformer/src/parser/utils/url.ts and and adf-schema/src/utils/url.ts, but has grown into something that is mostly unrelated to them, now.
    • 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).href would 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)