Package com.atlassian.bamboo.util
Class UrlUtils
- java.lang.Object
-
- com.atlassian.bamboo.util.UrlUtils
-
public class UrlUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static @NotNull String
appendSlashIfDoesntExist(@Nullable String theString)
Checks whether or not the given string has a '/' character as the last character, and appends one if it doesn'tstatic String
constructBaseUrl(javax.servlet.http.HttpServletRequest request)
Attempts to construct a baseUrl using theHttpServletRequest
object.static String
correctlyFormatUrl(String host)
static @NotNull URL
createUrl(@NotNull String url)
static @NotNull URL
createUrl(@NotNull String context, @NotNull String formActionDestination)
static @NotNull com.google.common.collect.Multimap<String,String>
extractQueryParams(@NotNull String url)
static @NotNull com.google.common.collect.Multimap<String,String>
extractQueryParams(@NotNull URI uri)
static @NotNull com.google.common.collect.Multimap<String,String>
extractQueryParams(@NotNull URL url)
static @Nullable String
extractSingleQueryParam(@NotNull String url, @NotNull String paramName)
static @Nullable String
extractSingleQueryParam(@NotNull URL url, @NotNull String paramName)
static String
getPathUnderContext(@NotNull String url, @NotNull String context)
Deprecated.static boolean
hasXssRelatedCharacters(@Nullable String string)
static boolean
isSameOrigin(@NotNull URL url, @NotNull URL origin)
static @NotNull String
prependSlashIfDoesntExist(@Nullable String theString)
Checks whether or not the given string has a '/' character as the first character, and puts one in if it doesn'tstatic @Nullable String
replaceOrInsertParamValue(String queryString, String newParamValue)
static String
replacePlanResultKeyInUrl(String url, PlanKey planKey, int newBuildNumber)
static @NotNull String
sanitizeUri(@NotNull String uri)
Removes XSS related characters from URI: backslash, double and single quotes, angle brackets.static @NotNull String
stripLeadingSlashes(@Nullable String toStrip)
Strips any leading '/' characters off the front of the string, if any.static @NotNull String
stripQueryAndRef(@NotNull String url)
static @NotNull String
stripTailingSlashes(@Nullable String toStrip)
Strips any leading '/' characters off the end of the string, if any.
-
-
-
Method Detail
-
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)
-
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)
Deprecated.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 com.google.common.collect.Multimap<String,String> extractQueryParams(@NotNull @NotNull URL url)
-
extractQueryParams
@NotNull public static @NotNull com.google.common.collect.Multimap<String,String> extractQueryParams(@NotNull @NotNull String url)
-
extractQueryParams
@NotNull public static @NotNull com.google.common.collect.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 checkorigin
- 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 context, @NotNull @NotNull String formActionDestination)
-
constructBaseUrl
public static String constructBaseUrl(javax.servlet.http.HttpServletRequest request)
Attempts to construct a baseUrl using theHttpServletRequest
object.- Parameters:
request
- The incoming http request- Returns:
- a string containing the absolute base URL
-
hasXssRelatedCharacters
public static boolean hasXssRelatedCharacters(@Nullable @Nullable String string)
-
-