This is an automated email from the ASF dual-hosted git repository.
borinquenkid pushed a commit to branch
refactor/java-to-groovy-grails-web-url-mappings
in repository https://gitbox.apache.org/repos/asf/grails-core.git
The following commit(s) were added to
refs/heads/refactor/java-to-groovy-grails-web-url-mappings by this push:
new 77a61b2116 fix(web-url-mappings): compare the other mapping info's
fields in equals
77a61b2116 is described below
commit 77a61b2116ea668f6fa6a5f2c56bf6a73d158288
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Tue Oct 13 06:07:15 2026 -0500
fix(web-url-mappings): compare the other mapping info's fields in equals
DefaultUrlMappingInfo.equals compared its own raw fields with the other
instance's accessors, which resolve closures and apply the URL converter.
Two infos built from the same closure were therefore never equal. Read the
fields on both sides, as the Java original did.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
---
.../web/mapping/DefaultUrlMappingInfo.groovy | 20 ++---
.../mapping/DefaultUrlMappingInfoEqualsSpec.groovy | 92 ++++++++++++++++++++++
2 files changed, 102 insertions(+), 10 deletions(-)
diff --git
a/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultUrlMappingInfo.groovy
b/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultUrlMappingInfo.groovy
index b3edc95305..ada7b21ca6 100644
---
a/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultUrlMappingInfo.groovy
+++
b/grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/DefaultUrlMappingInfo.groovy
@@ -246,17 +246,17 @@ class DefaultUrlMappingInfo extends
AbstractUrlMappingInfo {
DefaultUrlMappingInfo that = (DefaultUrlMappingInfo) o
- if (actionName != null ? !actionName.equals(that.actionName) :
that.actionName != null) return false
- if (controllerName != null ?
!controllerName.equals(that.controllerName) : that.controllerName != null)
+ if (actionName != null ? !actionName.equals(that.@actionName) :
that.@actionName != null) return false
+ if (controllerName != null ?
!controllerName.equals(that.@controllerName) : that.@controllerName != null)
return false
- if (httpMethod != null ? !httpMethod.equals(that.httpMethod) :
that.httpMethod != null) return false
- if (id != null ? !id.equals(that.id) : that.id != null) return false
- if (namespace != null ? !namespace.equals(that.namespace) :
that.namespace != null) return false
- if (pluginName != null ? !pluginName.equals(that.pluginName) :
that.pluginName != null) return false
- if (redirectInfo != null ? !redirectInfo.equals(that.redirectInfo) :
that.redirectInfo != null) return false
- if (uri != null ? !uri.equals(that.uri) : that.uri != null) return
false
- if (version != null ? !version.equals(that.version) : that.version !=
null) return false
- if (viewName != null ? !viewName.equals(that.viewName) : that.viewName
!= null) return false
+ if (httpMethod != null ? !httpMethod.equals(that.@httpMethod) :
that.@httpMethod != null) return false
+ if (id != null ? !id.equals(that.@id) : that.@id != null) return false
+ if (namespace != null ? !namespace.equals(that.@namespace) :
that.@namespace != null) return false
+ if (pluginName != null ? !pluginName.equals(that.@pluginName) :
that.@pluginName != null) return false
+ if (redirectInfo != null ? !redirectInfo.equals(that.@redirectInfo) :
that.@redirectInfo != null) return false
+ if (uri != null ? !uri.equals(that.@uri) : that.@uri != null) return
false
+ if (version != null ? !version.equals(that.@version) : that.@version
!= null) return false
+ if (viewName != null ? !viewName.equals(that.@viewName) :
that.@viewName != null) return false
return true
}
diff --git
a/grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/DefaultUrlMappingInfoEqualsSpec.groovy
b/grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/DefaultUrlMappingInfoEqualsSpec.groovy
new file mode 100644
index 0000000000..e6a65b2b64
--- /dev/null
+++
b/grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/DefaultUrlMappingInfoEqualsSpec.groovy
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.grails.web.mapping
+
+import spock.lang.Specification
+
+import grails.web.mapping.UrlMappingData
+
+/**
+ * Two infos built from the same mapping values are equal, even when the
values are
+ * closures or names that the info's accessors resolve to something else.
+ */
+class DefaultUrlMappingInfoEqualsSpec extends Specification {
+
+ private DefaultUrlMappingInfo info(Object controller, Object action,
Object namespace = null, Object plugin = null, Object view = null) {
+ new DefaultUrlMappingInfo(null, controller, action, namespace, plugin,
view, [:], Stub(UrlMappingData), null)
+ }
+
+ void 'infos built from the same closure values are equal'() {
+ given:
+ Closure controller = { -> 'books' }
+ Closure action = { -> 'list' }
+ Closure namespace = { -> 'admin' }
+
+ expect:
+ info(controller, action, namespace) == info(controller, action,
namespace)
+ info(controller, action, namespace).hashCode() == info(controller,
action, namespace).hashCode()
+ }
+
+ void 'infos built from different closures are not equal'() {
+ expect:
+ info({ -> 'books' }, 'list') != info({ -> 'books' }, 'list')
+ }
+
+ void 'infos built from the same names are equal'() {
+ expect:
+ info('book', 'list', 'admin', 'myPlugin') == info('book', 'list',
'admin', 'myPlugin')
+ }
+
+ void 'infos differing in any name are not equal'() {
+ expect:
+ info('book', 'list') != info('author', 'list')
+ info('book', 'list') != info('book', 'show')
+ info('book', 'list', 'one') != info('book', 'list', 'two')
+ info('book', 'list', null, 'one') != info('book', 'list', null, 'two')
+ }
+
+ void 'view mappings compare by view'() {
+ given:
+ Closure view = { -> '/index' }
+
+ expect:
+ new DefaultUrlMappingInfo(view, [:], Stub(UrlMappingData), null) ==
new DefaultUrlMappingInfo(view, [:], Stub(UrlMappingData), null)
+ new DefaultUrlMappingInfo('/a', [:], Stub(UrlMappingData), null) !=
new DefaultUrlMappingInfo('/b', [:], Stub(UrlMappingData), null)
+ }
+
+ void 'uri mappings compare by uri'() {
+ given:
+ Closure uri = { -> '/somewhere' }
+
+ expect:
+ new DefaultUrlMappingInfo(uri, Stub(UrlMappingData), null) == new
DefaultUrlMappingInfo(uri, Stub(UrlMappingData), null)
+ new DefaultUrlMappingInfo('/a', Stub(UrlMappingData), null) != new
DefaultUrlMappingInfo('/b', Stub(UrlMappingData), null)
+ }
+
+ void 'an info is equal to itself and not to other types'() {
+ given:
+ DefaultUrlMappingInfo info = info('book', 'list')
+
+ expect:
+ info == info
+ info != null
+ info != 'book'
+ }
+
+}