Skip to content

Commit c226aae

Browse files
authored
Fixed exception expectation in testDeeplyNestedElements (#606)
1 parent d5dd9fe commit c226aae

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/test/java/org/apache/xml/security/test/dom/parser/XMLParserEdgeCasesTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.xml.security.utils.XMLUtils;
2323
import org.junit.jupiter.api.Test;
2424
import org.w3c.dom.Document;
25+
import org.xml.sax.SAXParseException;
2526

2627
import java.io.ByteArrayInputStream;
2728
import java.nio.charset.StandardCharsets;
@@ -153,10 +154,15 @@ void testDeeplyNestedElements() {
153154
try {
154155
XMLUtils.read(bais, false);
155156
} catch (XMLParserException e) {
156-
// Stack overflow protection is acceptable
157-
assertTrue(e.getMessage().contains("depth") ||
158-
e.getMessage().contains("stack") ||
159-
e.getMessage().contains("nested"),
157+
/*
158+
* Stack overflow protection is acceptable - in this case there will be a parent
159+
* SAXParseException with a specific text.
160+
*/
161+
assertTrue(e.getCause() instanceof SAXParseException);
162+
SAXParseException saxEx = (SAXParseException) e.getCause();
163+
assertTrue(saxEx.getMessage().contains("depth") ||
164+
saxEx.getMessage().contains("stack") ||
165+
saxEx.getMessage().contains("nested"),
160166
"Deep nesting should trigger protection");
161167
}
162168
}, "Parser should handle deep nesting gracefully");

0 commit comments

Comments
 (0)