codeconsole commented on code in PR #16732:
URL: https://github.com/apache/grails-core/pull/16732#discussion_r4367610759


##########
grails-bootstrap/src/main/groovy/org/grails/config/NavigableMap.groovy:
##########
@@ -151,11 +198,17 @@ class NavigableMap implements Map<String, Object>, 
Cloneable {
             if (parseFlatKeys) {
                 String[] keyParts = sourceKey.split(/\./)
                 if (keyParts.length > 1) {
-                    mergeMapEntry(rootMap, path, targetMap, sourceKey, 
sourceValue, parseFlatKeys)
+                    if (!path) {

Review Comment:
   Fixed in 1f16fd0ec0. The `if (!path)` guard skipped the whole first pass, 
and for an indexed key that pass was the only thing building the container. The 
two passes are gone for indexed keys: a key with a subscript is now merged 
whole, by a `mergeIndexedEntry` that puts the container into the nested map 
that owns it and the same object under its flat key at the root, and writes a 
flat key for the element each subscript steps through and for the value. After 
`merge([a: ['rows[0].name': 'row']])`, `getProperty('a.rows', List)`, 
`navigate('a', 'rows')` and `config.a.rows` are the one list `[[name: 'row']]`, 
and `getProperty('a.rows[0]', Map)` and `getProperty('a.rows[0].name')` read as 
before. The second pass had been building a `rows[0]` block beside the list, at 
the root as well: `merge(['a.rows[0].name': 'row'])`, the form a YAML sequence 
of maps takes, left `navigate('a', 'rows')` `null` on the property source's map 
on every line; the re-merge of that map into the config happened
  to turn the block into a list element, which is why a loaded 
`application.yml` read correctly while a direct `merge` did not. Pinned in 
`NavigableMapSpec` for the root form, the nested form, two indexes, a map 
subscript, an index alone and a dotted container name, in 
`PropertySourcesConfigSpec` with `getProperty('a.rows', List)` for both forms 
and for a loaded YAML sequence, and in `NavigableMapPropertySourceSpec`, since 
the property source now sees a flat key for the element map and must not 
present it as a property.
   
   9810580858 covers the list written the other way round: a list merged as a 
value, `merge([a: [rows: [[name: 'new']]]])` or `config.a.rows = [...]`, wrote 
no element keys, so after it replaced a list written by indexed keys 
`getProperty('a.rows[0].name')` still answered from the old elements. It now 
writes the element keys and drops those of the list it replaces.
   



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