jamesfredley commented on code in PR #16772:
URL: https://github.com/apache/grails-core/pull/16772#discussion_r4383315406


##########
grails-bootstrap/src/main/groovy/org/grails/config/NavigableMap.groovy:
##########
@@ -380,15 +380,30 @@ class NavigableMap implements Map<String, Object>, 
Cloneable {
     }
 
     private void flattenKeys(Map<? extends Object, Object> flatConfig, Map 
currentMap, List<String> path, boolean forceStrings) {
+        flattenKeys(flatConfig, currentMap, path, forceStrings, this, 0)
+    }
+
+    /**
+     * Writes the entries of a map under their names. An entry of a map 
written by map subscripts, such as {@code /api/**}
+     * of {@code app.routes[/api/**]}, is written under the bracketed flat key 
that the nearest enclosing nested map holds
+     * for it, relative to that map, and so is skipped here, where it would be 
written again under the dotted name
+     * {@code app.routes./api/**}, which Spring Boot binds as {@code api}; so 
is a dotted flat key of the map itself that
+     * names the same entry, as a merge of a block holding the entry writes 
{@code app.routes./api/**} at the root.
+     */
+    private void flattenKeys(Map<? extends Object, Object> flatConfig, Map 
currentMap, List<String> path, boolean forceStrings,
+                             NavigableMap owner, int ownerDepth) {
+        NavigableMap childOwner = currentMap instanceof NavigableMap ? 
(NavigableMap) currentMap : owner
+        int childOwnerDepth = currentMap instanceof NavigableMap ? path.size() 
: ownerDepth
+        List<String> relativePath = path.subList(ownerDepth, path.size())
         currentMap.each { key, value ->
             String stringKey = String.valueOf(key)
-            if (value != null) {
+            if (value != null && !isNamedInBrackets(owner, relativePath, 
stringKey)) {

Review Comment:
   `merge(['routes[api]': [target: 'http://localhost'], 'routes[api].enabled': 
'true'], true)` exports only `routes[api].enabled=true`. The nested map still 
has `target`, but the bracketed alias is an incomplete map, and this skip then 
drops the complete one.
   
   Keep every field in the bracketed map before skipping its dotted twin. 
Please assert both `target` and `enabled` are exported.
   
   A later dotted write has the same gap. `merge(['app.routes[k]': null], 
true)` then `merge(['app.routes.k': 'new'], true)` leaves the nested value as 
`new` and exports nothing.



-- 
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]

Reply via email to