Class UrlUtils

java.lang.Object
com.atlassian.bamboo.util.UrlUtils

public class UrlUtils extends Object
  • Method Details

    • sanitizeUri

      @NotNull public static @NotNull String sanitizeUri(@NotNull @NotNull String uri)
      Removes XSS related characters from URI: backslash, double and single quotes, angle brackets.
      Parameters:
      uri -
      Returns:
    • replaceOrInsertParamValue

      @Nullable public static @Nullable String replaceOrInsertParamValue(String queryString, String newParamValue)
    • replacePlanResultKeyInUrl

      public static String replacePlanResultKeyInUrl(String url, PlanKey planKey, int newBuildNumber)
    • correctlyFormatUrl

      public static String correctlyFormatUrl(String host)
    • stripLeadingSlashes

      @NotNull public static @NotNull String stripLeadingSlashes(@Nullable @Nullable String toStrip)
      Strips any leading '/' characters off the front of the string, if any.
      Parameters:
      toStrip - - the string to strip
      Returns:
      the string without the leading '/' characters
    • stripTailingSlashes

      @NotNull public static @NotNull String stripTailingSlashes(@Nullable @Nullable String toStrip)
      Strips any leading '/' characters off the end of the string, if any.
      Parameters:
      toStrip - - the string to strip
      Returns:
      the string without the end '/' characters
    • appendSlashIfDoesntExist

      @NotNull public static @NotNull String appendSlashIfDoesntExist(@Nullable @Nullable String theString)
      Checks whether or not the given string has a '/' character as the last character, and appends one if it doesn't
      Parameters:
      theString - to check and append.
      Returns:
      the original string with the extra '/' if required.
    • prependSlashIfDoesntExist

      @NotNull public static @NotNull String prependSlashIfDoesntExist(@Nullable @Nullable String theString)
      Checks whether or not the given string has a '/' character as the first character, and puts one in if it doesn't
      Parameters:
      theString - to check and prepend.
      Returns:
      the original string with the extra '/' if required.
    • stripQueryAndRef

      @NotNull public static @NotNull String stripQueryAndRef(@NotNull @NotNull String url)
    • getPathUnderContext

      @Deprecated public static String getPathUnderContext(@NotNull @NotNull String url, @NotNull @NotNull String context)
      Given an URL which may: - include scheme,host and optionally port - start directly with context - start with an arbitrary path under a context this method returns the path under context. It should not be used for security purposes, because it operates on best effort basis - including returning the URL without modifications if context is not found .
      See Also:
      • for context description
    • extractQueryParams

      @NotNull public static @NotNull Multimap<String,String> extractQueryParams(@NotNull @NotNull URL url)
    • extractQueryParams

      @NotNull public static @NotNull Multimap<String,String> extractQueryParams(@NotNull @NotNull String url)
    • extractQueryParams

      @NotNull public static @NotNull Multimap<String,String> extractQueryParams(@NotNull @NotNull URI uri)
    • extractSingleQueryParam

      @Nullable public static @Nullable String extractSingleQueryParam(@NotNull @NotNull URL url, @NotNull @NotNull String paramName)
    • extractSingleQueryParam

      @Nullable public static @Nullable String extractSingleQueryParam(@NotNull @NotNull String url, @NotNull @NotNull String paramName)
    • isSameOrigin

      public static boolean isSameOrigin(@NotNull @NotNull URL url, @NotNull @NotNull URL origin)
      Parameters:
      url - the url to check
      origin - the origin to check against.
      Returns:
      true if the given url is the same origin as the given origin url otherwise returns false.
    • createUrl

      @NotNull public static @NotNull URL createUrl(@NotNull @NotNull String url)
    • createUrl

      @NotNull public static @NotNull URL createUrl(@NotNull @NotNull String context, @NotNull @NotNull String formActionDestination)
    • constructBaseUrl

      public static String constructBaseUrl(javax.servlet.http.HttpServletRequest request)
      Attempts to construct a baseUrl using the HttpServletRequest object.
      Parameters:
      request - The incoming http request
      Returns:
      a string containing the absolute base URL
    • hasXssRelatedCharacters

      public static boolean hasXssRelatedCharacters(@Nullable @Nullable String string)