jamesfredley commented on code in PR #16772:
URL: https://github.com/apache/grails-core/pull/16772#discussion_r4392597155
##########
grails-bootstrap/src/main/groovy/org/grails/config/NavigableMap.groovy:
##########
@@ -420,6 +435,81 @@ class NavigableMap implements Map<String, Object>,
Cloneable {
}
}
+ /**
+ * Whether a bracketed flat key exports the entry, so that the walk skips
its dotted name. The entry {@code /api/**} of
+ * {@code routes} is exported by {@code routes[/api/**]}, held by the
nearest enclosing nested map, when that key
+ * exports every name and value the entry would, and the walked map holds
no flat key under the entry's dotted name,
+ * {@code app.routes./api/**}, or under the dotted name of a value below
the entry, with another value. A flat key of
+ * the map itself, such as {@code app.routes./api/**}, is exported by the
bracketed key that splits it at one of its
+ * dots, {@code app.routes[/api/**]}, when that key exports the same value
and no flat key below it disagrees. Where the bracketed key holds less, or a
value a later write replaced, or the dotted names hold
+ * values that differ, the dotted names are exported too, and the one
written last is the one exported under them.
+ */
+ private boolean isExportedInBrackets(NavigableMap owner, List<String>
path, List<String> relativePath, String key, Object value) {
+ if (relativePath) {
+ String bracketedKey =
"${relativePath.join('.')}[${key}]".toString()
+ if (!owner.containsKey(bracketedKey) ||
!exportsAll(owner.get(bracketedKey), value)) {
+ return false
+ }
+ return agreesWithFlatKeys("${path.join('.')}.${key}".toString(),
value)
+ }
+ for (int dot = key.indexOf('.'); dot > 0; dot = key.indexOf('.', dot +
1)) {
+ String bracketedKey = "${key.substring(0,
dot)}[${key.substring(dot + 1)}]".toString()
+ if (owner.containsKey(bracketedKey) &&
exportsAll(owner.get(bracketedKey), value)) {
Review Comment:
Merging `a[b.c]=new`, then `a.b[c]=old`, then `a.b.c=new` makes
`toFlatConfig()` and `toProperties()` emit `a.b.c=old`. Lookup and `navigate`
return `new`. The dotted entry is skipped because it matches `a[b.c]`, and the
stale `a.b` map is what gets exported.
Keep the dotted entry when another alias disagrees. Please assert this order.
--
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]