grails-core icon indicating copy to clipboard operation
grails-core copied to clipboard

Grails 6.2.3 Redirect issue when redirected to a url created using LinkGenerator.link

Open imranmir opened this issue 2 months ago • 6 comments

Expected Behavior

If a url is created using grailsLinkGenerator String url = grailsLinkGenerator.link(controller: 'menu', action: 'home')
and the url (/red/menu/home) is used to redirect like: redirect(url: url) 404 occurs as the redirect appends the application name again to the url, e.g., http://localhost:8080/red/red/menu/home

This looks to be a regression and asit works in Grails 5. Attaching a Grails 5 and Grails 6 application for bug reproduction.

Actual Behaviour

Redirect should not append the application name again.

Steps To Reproduce

Please checkout the following Grails 6.2.3 project: https://github.com/imranmir/redirect-issue Boot run the application Hit the following url: http://localhost:8080/red/test/index This should ideally have redirected to http://localhost:8080/red/menu/home, but instead it tries to redirect to http://localhost:8080/red/red/menu/home

Environment Information

OSX openjdk 11.0.27

Example Application

https://github.com/imranmir/redirect-issue

Version

6.2.3

Working redirect on Grails 5 application: https://github.com/imranmir/green-app-

imranmir avatar Oct 10 '25 05:10 imranmir

The bug must have been introduced in Grails 6.1.2 and it seems to also be present in Grails 7.0.0 ...

dauer avatar Oct 27 '25 15:10 dauer

Hi, In your code, you forget absolute:false.

The bug introduced between grails 5.2X (https://github.com/apache/grails-core/blob/5.2.x/grails-web-url-mappings/src/main/groovy/grails/web/mapping/ResponseRedirector.groovy#L125) and grails 5.3.X (https://github.com/apache/grails-core/blob/5.3.x/grails-web-url-mappings/src/main/groovy/grails/web/mapping/ResponseRedirector.groovy#L125)

Noirtam avatar Nov 12 '25 15:11 Noirtam

Probably a dumb question, but may I ask the use case for first creating a url with the LinkGenerator and then passing that url to redirect() (where the LinkGenerator will be invoked again) instead of calling redirect() directly?

From the example application provided: https://github.com/imranmir/redirect-issue

class TestController {

    LinkGenerator grailsLinkGenerator

    def index() {
        def url = grailsLinkGenerator.link(controller: 'menu', action: 'home')
        redirect(url: url)
   }

    // vs

    def index2() {
        redirect(controller: 'menu', action: 'home')
    }
}

matrei avatar Nov 13 '25 16:11 matrei

The linkGenerator.link call comes from a legacy helper method that’s responsible for generating links dynamically. Redirecting with that link is just one of the things it does — the same link is also passed to JavaScript and used in a few other places. So we end up reusing that generated link in redirect() instead of calling redirect() directly.

imranmir avatar Nov 18 '25 05:11 imranmir

Fixed by https://github.com/apache/grails-core/pull/15227

jdaugherty avatar Nov 19 '25 15:11 jdaugherty

Reverts changes for https://github.com/apache/grails-core/issues/11673

jdaugherty avatar Nov 19 '25 15:11 jdaugherty