UrlMapping doesn't work on root with controller (Grails 3.x - Grails 4.0.6)
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
Hello,
Either i do not understand how UrlMapping is working in Grails or is this a weird bug since Grails 3.x
There is also an old questtion in Stackoverflow on this topic.
https://stackoverflow.com/questions/57548705/grails-4-url-mapping-for-root-not-working
But the problem has noting to do with spring security as it is suggested there.
### Steps to Reproduce
In the UrlMappings.grooy replace/create the following mapping:
```
static mappings = {
"/inhabituel"(controller: "home") {
lang = "fr"
}
"/$controller/$action?/$id?(.$format)?"{
constraints {
// apply constraints here
}
}
"/"(controller: "home")
"500"(view:'/error')
"404"(view:'/notFound')
}
```
create a redirect in any controller:
```
def doSomething() {
flash.message = "Job done"
redirect(controller: "home")
}
```
### Expected Behaviour
The expected behaviour is, that the "doSomething" action, redirect to the root:
example.com/doThings/doSomething should redirect to example.com and then the "home" controller is doing whatever it should do without to change the URL and the language.
So only an explict call to example.com/inhabituel should change the URL in the browser adress bar and change the language.
### Actual Behaviour
In Grails 2. the actual behaviour is the same as the expected behaviour.
It seems that since Grails 3.x till to the current 4.0.6 this doesn't work anymore.
The current behaviour is weird and i can not explain myself why it is happening.
**Any call to (controller: "home") cause that the "/inhabituel"(controller: "home") rule get involved.**
The order of the rules in the UrlMappings.grooy doesn't matter for the problem.
A workaround is:
replacing any:
```
redirect(controller: "home")
```
with
```
redirect(uri: "/")
```
That is working and creatre the expected behaviour. but i still can not see, why any call to (controller: "home") cause that the "/inhabituel"(controller: "home") rule get involved.
I created a couple of example applications: see below
Additional note (just in case):
I use to create a default Locale (see conf/spring/resources.groovy) but the problem is present without that too.
### Environment Information
- **Operating System**: all
- **Grails Version:** 3.x - 4.0.6
- **JDK Version:** all
### Example Application
Grails 2.5.6 https://github.com/DontPlayTheGame/example-grails256 (working as expected)
Not working as expected:
https://github.com/DontPlayTheGame/example-grails3116
https://github.com/DontPlayTheGame/example-grails3311
https://github.com/DontPlayTheGame/example-grails406
Contributor guide
Research direction
Start with UrlMappings.groovy and the controller action that calls redirect(controller: "home"). Compare the working Grails 2.5.6 example with the Grails 3.1.16, 3.3.11, and 4.0.6 examples, then trace how the "/" and "/inhabituel" mappings are selected. Done means controller-based redirects reach the root without applying the "/inhabituel" mapping, while the explicit path still changes the URL and language.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100