Copilot commented on code in PR #2711:
URL: https://github.com/apache/groovy/pull/2711#discussion_r3593629415


##########
subprojects/groovy-markdown/src/spec/test/groovy/markdown/MarkdownSlurperTest.groovy:
##########
@@ -153,4 +155,23 @@ class MarkdownSlurperTest {
         def doc = new MarkdownSlurper().parseText(md)
         assert doc.tables.isEmpty()
     }
+
+    @Test
+    void testDeeplyNestedInputRejected() {
+        // a small (~5 KB) document nests block quotes thousands deep; the 
recursive
+        // document walk must not be driven into a StackOverflowError
+        def md = ('>' * 5000) + ' x'
+        def ex = assertThrows(MarkdownRuntimeException) { new 
MarkdownSlurper().parseText(md) }
+        assert ex.message.contains('nesting depth')
+    }
+
+    @Test
+    void testMaxNestingDepthConfigurable() {
+        def slurper = new MarkdownSlurper()
+        assert slurper.maxNestingDepth == 
MarkdownSlurper.DEFAULT_MAX_NESTING_DEPTH
+        slurper.maxNestingDepth = 3
+        assertThrows(MarkdownRuntimeException) { slurper.parseText(('>' * 10) 
+ ' x') }
+        // input within the limit still parses
+        assert slurper.parseText('> quoted').nodes[0].type == 'block_quote'
+    }

Review Comment:
   These new tests assume the default max nesting depth is in effect, but 
MarkdownSlurper allows overriding it via the `groovy.markdown.maxNestingDepth` 
system property at construction time. If the build JVM has that property set 
(or another test mutates it), `testDeeplyNestedInputRejected` may not throw and 
`testMaxNestingDepthConfigurable` may fail the default-value assertion. To keep 
the tests deterministic, save/clear/restore the system property around the 
assertions (similar to the JsonSlurper nesting-depth tests).



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