Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ class ResponseRedirector {

boolean permanent = getBooleanArgument(ARGUMENT_PERMANENT, arguments)
boolean moved = getBooleanArgument(ARGUMENT_MOVED, arguments, true)
boolean absolute = getBooleanArgument(ARGUMENT_ABSOLUTE, arguments, true)

final Map namedParameters = new LinkedHashMap<>(arguments)
// we generate a relative link with no context path so that the absolute can be calculated by combining the serverBaseURL
// which includes the contextPath
namedParameters.put(LinkGenerator.ATTRIBUTE_CONTEXT_PATH, BLANK)

boolean absolute = getBooleanArgument(ARGUMENT_ABSOLUTE, arguments, true)
// @Issue('11673')
if (absolute) namedParameters.put(LinkGenerator.ATTRIBUTE_CONTEXT_PATH, BLANK)

// If the request parameters contain "keepParamsWhenRedirect = true", then we add the original params. The
// new attribute can be used from UrlMappings to redirect from old URLs to new ones while keeping the params
Expand Down Expand Up @@ -129,7 +129,7 @@ class ResponseRedirector {
if (absolute) {
redirectURI = processedActualUri.contains('://') ? processedActualUri : serverBaseURL + processedActualUri
} else {
redirectURI = linkGenerator.contextPath + processedActualUri
redirectURI = processedActualUri
}

String redirectUrl = useJessionId ? response.encodeRedirectURL(redirectURI) : redirectURI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,26 @@ class RedirectNonAbsoluteURISpec extends AbstractUrlMappingsSpec {
cleanup:
RequestContextHolder.setRequestAttributes(null)
}

@Issue('15132')
void 'An "absolute=false" redirect not added context-path with url params'() {
given:
def linkGenerator = getLinkGeneratorWithContextPath {
"/$controller/$action?/$id?"()
}
def responseRedirector = new ResponseRedirector(linkGenerator)
HttpServletRequest request = Mock(HttpServletRequest) { lookup() >> GrailsWebMockUtil.bindMockWebRequest() }
HttpServletResponse response = Mock(HttpServletResponse)

when: 'redirecting with absolute=false where context-path is set'
String url = linkGenerator.link(controller:"test", action: "foo")
responseRedirector.redirect(request, response, [url:url, absolute: false])

then: 'the partial URL includes context-path'
1 * response.setHeader(HttpHeaders.LOCATION, "${CONTEXT_PATH}/test/foo")

cleanup:
RequestContextHolder.setRequestAttributes(null)
}

}
Loading