Grails 4.0.4: Namespaced controllers being matched without providing namespace to the mapping
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
Thanks for reporting an issue for Grails framework, please review the task list below before submitting the
issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed.
NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Stack Overflow (http://stackoverflow.com/tags/grails) or Slack (http://slack-signup.grails.org). DO NOT use the issue tracker to ask questions.
### Task List
- [x] Steps to reproduce provided
- [x] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)
### Steps to Reproduce
1. Perform run-app on the linked repository
2. Visit the path http://localhost:8080/namespaced-should-not-work-but-works
### Expected Behaviour
The documentation (https://docs.grails.org/4.0.4/guide/theWebLayer.html#namespacedControllers) says:
> When resolving a URL mapping (forward or reverse) to a namespaced controller, a mapping **will only match** if the namespace has been provided. If the application provides several controllers with the same name in different packages, at most 1 of them may be defined without a namespace property. If there are multiple controllers with the same name that do not define a namespace property, the framework will not know how to distinguish between them for forward or reverse mapping resolutions.
According to the doc, a mapping for a namespaced controller will **only** match if the namespace has been provided, so therefore /namespaced-should-not-work-but-works should not work because I did not provide a namespace to the mapping but it does.
Expected behavior of the example app:
|Path|Expected Result|
|---|---|
|/namespaced-should-not-work-but-works|**Should not work**|
|/namespaced|Should work|
|/namespaced-should-not-work|Should not work|
|/ordinary|Should work|
|/ordinary-should-not-work|Should not work|
I am relying on this behavior to avoid accidentally mismatching a controller.
### Actual Behaviour
However, when I added a mapping for a namespaced controller **without** providing the namespace, it still worked. The "/namespaced-should-not-work-but-works" URL mapping defined in the example app still worked.
Actual behavior of the example app:
|Path|Actual Result|
|---|---|
|/namespaced-should-not-work-but-works|**Works**|
|/namespaced|Works|
|/namespaced-should-not-work|Does not work|
|/ordinary|Works|
|/ordinary-should-not-work|Does not work|
### Environment Information
- **Operating System**: macOS Catalina 10.15.4
- **Grails Version:** 4.0.4
- **JDK Version:** JDK 1.8 Update 151
- **Container Version (If Applicable):** N/A
### Example Application
- https://github.com/rocketmiles/grails-test-namespaced-controller
Contributor guide
Research direction
Start with the linked example application and reproduce the listed namespaced and ordinary URL paths. Trace the URL-mapping and namespaced-controller resolution entry points, then add coverage showing that a mapping without a namespace does not match a namespaced controller while the documented paths continue to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100