-
Couldn't load subscription status.
- Fork 38.8k
Description
Nicolas Demengel opened SPR-7589 and commented
Hi people,
I might have found an odd behavior in the AbstractUrlHandlerMapping class : given two controllers, one annotated with @RequestMapping("/**") and the another one annotated with @RequestMapping("/access/{resourceType}/{resourceSubType}/{resourceName}"), when the path "/access/document/text/sometextdocument" is evaluated I would expect the second controller to be chosen to handle the request but it is the first one that is taken.
Looking at the code of AbstractUrlHandlerMapping.lookupHandler() one can see that when several patterns are found that match the path, they are ordered using an AntPatternComparator to find the most pertinent one for it. Digging in further, this comparator orders patterns based on their level of incertitude, counting the occurrences of wildcards and brackets. In my opinion it should read patterns as we do (i.e. from left to right in our countries) to see if the pattern start makes it more suitable to handle the path that is evaluated.
I attached a JUnit test to illustrate my point.
Thanks
Affects: 3.0.4
Attachments:
- AntPatternComparatorTest.java (1.45 kB)
Issue Links:
- RequestMapping with 3 PathVariable doesn't work [SPR-6741] #11407 RequestMapping with 3 PathVariable doesn't work ("duplicates")
- AntPathMatcher.AntPatternComparator algorithm wrong for hierarchical matches [SPR-8683] #13325 AntPathMatcher.AntPatternComparator algorithm wrong for hierarchical matches
1 votes, 1 watchers