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


##########
grails-core/src/test/groovy/org/grails/config/PropertySourcesConfigSpec.groovy:
##########
@@ -132,9 +132,33 @@ class PropertySourcesConfigSpec extends Specification {
         config.getProperty('.plain.nested.value.') == 'found'
         config.getProperty('...') == null
 
-        and: "a key that runs past a scalar answers with that scalar, as it 
always has"
-        // Grails 8 behaviour, pinned on purpose: apache/grails-core#16732 
makes such a key absent on 9.0.x
-        config.getProperty('plain.nested.value.deeper') == 'found'
-        config.containsProperty('plain.nested.value.deeper')
+        and: "a key that runs past a scalar is absent, where Grails 8 answered 
with the scalar"
+        config.getProperty('plain.nested.value.deeper') == null
+        !config.containsProperty('plain.nested.value.deeper')
+    }
+
+    void 'a dotted key that runs past a value that is not a map is absent'() {
+        given: "a scalar, a list and a closure, the value shapes 
application.yml and application.groovy produce"
+        def constraints = { nullable true }
+        def config = new PropertySourcesConfig([
+                server: [url: 'http://localhost', ports: [8080, 8443]],
+                grails: [gorm: ['default': [constraints: constraints]]]
+        ])
+
+        expect: "each value resolves itself"
+        config.getProperty('server.url') == 'http://localhost'
+        config.getProperty('server.ports', List) == [8080, 8443]
+        config.getProperty('grails.gorm.default.constraints', 
Closure).is(constraints)
+
+        and: "a key that names a child of any of them is absent rather than 
the value"
+        config.getProperty('server.url.port') == null
+        config.getProperty('server.url.port', String, 'none') == 'none'
+        config.getProperty('server.ports.0') == null

Review Comment:
   Done in 08c7f0543f, with the guide and skill in 1d08fa3fc3. e536f6c580 
merges 9.0.x in first, since the branch had fallen behind.
   
   - `getProperty` and `navigate` step into a list when the next segment is a 
whole number within it. `server.ports.0` is `8080` and `navigate('server', 
'ports', '0')` agrees.
   - `ports[0]` names the element of the list under `ports` when the map holds 
no key of that name, so `server.ports[0]` now answers for a list from 
`application.groovy` too.
   - A list of maps reads into its elements: `app.rows.0.name`.
   - An index past the end, a negative or signed number, or any other segment 
after a list stays absent. A map whose keys are numbers reads as before.
   
   Tests:
   - `PropertySourcesConfigSpec` checks a list held whole and a list from 
`application.yml`.
   - It compares with a `StandardEnvironment` with 
`ConfigurationPropertySources` attached, which gives `8080` for 
`server.ports.0` and `null` past the end, as the config now does.
   - It also covers a map with numeric keys.
   - `NavigableMapSpec` covers `navigate`.
   
   The new features fail at 07a31f2ec3. `grails-bootstrap` (308) and 
`grails-core` (1087) pass.
   
   Section 20 now describes the list case with an example and a required action 
for code that read the whole list through `server.ports.0`. It also drops the 
earlier advice to read the element from the whole list, which the index makes 
unnecessary.
   



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