Skip to content

Commit d23e7ea

Browse files
author
sebastien matrion
committed
Undo the last commit and add a potential fix for @issue('11673')
1 parent 7b27d17 commit d23e7ea

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

grails-web-url-mappings/src/main/groovy/grails/web/mapping/ResponseRedirector.groovy

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@ class ResponseRedirector {
9494
boolean permanent = getBooleanArgument(ARGUMENT_PERMANENT, arguments)
9595
boolean moved = getBooleanArgument(ARGUMENT_MOVED, arguments, true)
9696

97+
98+
boolean absolute = getBooleanArgument(ARGUMENT_ABSOLUTE, arguments, true)
99+
97100
final Map namedParameters = new LinkedHashMap<>(arguments)
98101
// we generate a relative link with no context path so that the absolute can be calculated by combining the serverBaseURL
99102
// which includes the contextPath
100-
namedParameters.put(LinkGenerator.ATTRIBUTE_CONTEXT_PATH, BLANK)
101-
102-
boolean absolute = getBooleanArgument(ARGUMENT_ABSOLUTE, arguments, true)
103+
// @Issue('11673')
104+
if(absolute) namedParameters.put(LinkGenerator.ATTRIBUTE_CONTEXT_PATH, BLANK)
103105

104106
// If the request parameters contain "keepParamsWhenRedirect = true", then we add the original params. The
105107
// new attribute can be used from UrlMappings to redirect from old URLs to new ones while keeping the params

grails-web-url-mappings/src/test/groovy/grails/web/mapping/RedirectNonAbsoluteURISpec.groovy

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,26 @@ class RedirectNonAbsoluteURISpec extends AbstractUrlMappingsSpec {
9494
RequestContextHolder.setRequestAttributes(null)
9595
}
9696

97+
@Issue('11673')
98+
void 'An "absolute=false" redirect includes context-path in Location header'() {
99+
given:
100+
def linkGenerator = getLinkGeneratorWithContextPath {
101+
"/$controller/$action?/$id?"()
102+
}
103+
def responseRedirector = new ResponseRedirector(linkGenerator)
104+
HttpServletRequest request = Mock(HttpServletRequest) { lookup() >> GrailsWebMockUtil.bindMockWebRequest() }
105+
HttpServletResponse response = Mock(HttpServletResponse)
106+
107+
when: 'redirecting with absolute=false where context-path is set'
108+
responseRedirector.redirect(request, response, [controller: 'test', action: 'foo', absolute: false])
109+
110+
then: 'the partial URI includes context-path'
111+
1 * response.setStatus(302)
112+
1 * response.setHeader(HttpHeaders.LOCATION, CONTEXT_PATH + '/test/foo')
113+
114+
cleanup:
115+
RequestContextHolder.setRequestAttributes(null)
116+
}
97117

98118
@Issue('15132')
99119
void 'An "absolute=false" redirect not added context-path with url params'() {

0 commit comments

Comments
 (0)