codeconsole commented on code in PR #15542:
URL: https://github.com/apache/grails-core/pull/15542#discussion_r3047678348
##########
grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/mvc/AbstractGrailsControllerUrlMappings.groovy:
##########
@@ -225,30 +223,32 @@ abstract class AbstractGrailsControllerUrlMappings
implements UrlMappings {
ControllerKey controllerKey = new ControllerKey(info.namespace,
info.controllerName, info.actionName, info.pluginName)
GrailsControllerClass controllerClass = info ?
mappingsToGrailsControllerMap.get(controllerKey) : null
if (controllerClass) {
- def wrapped = new
GrailsControllerUrlMappingInfo(controllerClass, info)
- if (validateWildcardMappings && info.hasWildcardCaptures()) {
- wildcardActionMatches.add(wrapped)
- } else {
- otherMatches.add(wrapped)
- if (!hasLiteralControllerMatch) {
- // A literal match has no URL-captured parameters
beyond standard routing params
- def params = info.parameters
- hasLiteralControllerMatch = params == null ||
params.keySet().every { it in ROUTING_PARAMS }
- }
- }
+ matches.add(new
GrailsControllerUrlMappingInfo(controllerClass, info))
} else if (!validateWildcardMappings ||
!info.hasWildcardCaptures()) {
- otherMatches.add(info)
+ matches.add(info)
}
// else: wildcard-captured values didn't match a registered
controller/action — skip
}
- // Wildcard-resolved matches take priority over parameterized
catch-all matches
- // (e.g., $controller=feed beats $communitySlug=feed), but NOT over
literal path
- // matches (e.g., /community or post /invites) which are always more
specific
- if (hasLiteralControllerMatch) {
- (otherMatches + wildcardActionMatches) as UrlMappingInfo[]
- } else {
- (wildcardActionMatches + otherMatches) as UrlMappingInfo[]
+ // When wildcard validation is enabled, promote validated wildcard
matches
+ // (e.g., $action? resolving to a real action) only when they have
strictly fewer
+ // non-routing URL captures — meaning they matched a more specific URL
pattern.
+ // Same wildcard status: preserve URL matcher's original order (stable
sort).
+ // When validation is disabled, preserve original URL matcher order
entirely.
+ if (validateWildcardMappings) {
+ matches.sort(true) { a, b ->
Review Comment:
@jamesfredley yes, typically 2-5 matches for any given URL, so the sort is
sorting a tiny list. The nonRoutingParamCount() does a `keySet().count { }`
iteration over 1-3 params per call. For a 3-element sort, that's ~6 comparisons
× ~2 param iterations = ~12 operations. Negligible compared to the HTTP
overhead, regex matching in matchAll(), and controller dispatch that surround
it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]