Package com.atlassian.bamboo.util
Class UrlUtils
java.lang.Object
com.atlassian.bamboo.util.UrlUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic @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
static @NotNull URL
extractQueryParams
(@NotNull String url) extractQueryParams
(@NotNull URI uri) 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 Details
-
sanitizeUri
Removes XSS related characters from URI: backslash, double and single quotes, angle brackets.- Parameters:
uri
-- Returns:
-
replaceOrInsertParamValue
-
replacePlanResultKeyInUrl
-
correctlyFormatUrl
-
stripLeadingSlashes
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
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
-
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
-
extractQueryParams
-
extractQueryParams
-
extractSingleQueryParam
-
extractSingleQueryParam
-
isSameOrigin
- 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
-
createUrl
-
constructBaseUrl
Attempts to construct a baseUrl using theHttpServletRequest
object.- Parameters:
request
- The incoming http request- Returns:
- a string containing the absolute base URL
-
hasXssRelatedCharacters
-
UrlUtils.getPathUnderContext(java.lang.String, java.lang.String)