hk2166 commented on issue #12357:
URL: https://github.com/apache/grails-core/issues/12357#issuecomment-6579003991

   I'd like to work on this. It still happens on 7.2.x. I reproduced it with 
Grails' `YamlPropertySourceLoader` and `PropertySourcesConfig`, using this 
`application.yml`:
   
   ```yaml
   grails:
       serverURL: http://base.example
       plugin:
           springsecurity:
               active: true
   environments:
       development:
           grails:
   #            serverURL: http://dev.example
   ```
   
   In development, `config.getProperty('grails.plugin.springsecurity.active', 
Boolean)` returns `null`, and `config.grails` is an empty string.
   
   **Cause:**
   1. The YAML parser flattens the empty `grails:` key to 
`environments.development.grails = ""`.
   2. `YamlPropertySourceLoader.load` copies the entries of the current 
environment over the top-level keys, so the source gets `grails = ""` next to 
`grails.serverURL` and `grails.plugin.springsecurity.active`.
   3. `NavigableMap.merge` then merges `grails = ""` as a plain value, which 
replaces the whole `grails` map.
   
   8.0.x has the same loader and the same merge step.
   
   **Proposed fix:** in `NavigableMap.mergeMapEntry`, an empty value (`null` or 
`""`) no longer replaces a nested map that is already there, so a leftover key 
with nothing under it is harmless. A key that holds a value keeps being 
replaced as today, and so does an empty value for a key that isn't a map.
   
   **Tests:**
   - `NavigableMapSpec`: merging an empty value over a nested map keeps it, and 
over a plain value still replaces it.
   - A `YamlPropertySourceLoader` test with the YAML above.
   - A test where an environment block's empty key keeps the base config while 
its other keys still override it.
   
   I'd target 7.2.x and merge forward. `NavigableMap` was refactored on 8.0.x, 
so the merge-up would need the same check carried over. @jdaugherty @matrei, 
does that sound right?
   


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