mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:30:28 +00:00
Ignore DOCTYPE inside a multi-line comment body
XmlValidationModeDetector peeks at the start of an XML document to choose between DTD- and XSD-based validation, skipping any DOCTYPE that appears inside an XML comment. Prior to this commit, consumeCommentTokens() short-circuited a line with no start or end comment marker by returning it unchanged, even while already inside a multi-line comment. Such a body line was then treated as content, so a literal "DOCTYPE" word in the comment body caused an XSD document to be misdetected as DTD-based. This commit honors the "in comment" parse state in that early return so a comment body line is treated as empty content, completing the fix for gh-27915 which only covered comment markers on the same line. Closes gh-36948 Signed-off-by: junhyeong9812 <pickjog@gmail.com>
This commit is contained in:
+3
-1
@@ -151,7 +151,9 @@ public class XmlValidationModeDetector {
|
||||
private String consumeCommentTokens(String line) {
|
||||
int indexOfStartComment = line.indexOf(START_COMMENT);
|
||||
if (indexOfStartComment == -1 && !line.contains(END_COMMENT)) {
|
||||
return line;
|
||||
// If we are inside a multi-line comment, the entire line is comment
|
||||
// data and must not be treated as content.
|
||||
return (this.inComment ? "" : line);
|
||||
}
|
||||
|
||||
String result = "";
|
||||
|
||||
+2
-1
@@ -55,7 +55,8 @@ class XmlValidationModeDetectorTests {
|
||||
"xsdWithNoComments.xml",
|
||||
"xsdWithMultipleComments.xml",
|
||||
"xsdWithDoctypeInComment.xml",
|
||||
"xsdWithDoctypeInOpenCommentWithAdditionalCommentOnSameLine.xml"
|
||||
"xsdWithDoctypeInOpenCommentWithAdditionalCommentOnSameLine.xml",
|
||||
"xsdWithDoctypeInMultiLineCommentBody.xml"
|
||||
})
|
||||
void xsdDetection(String fileName) throws Exception {
|
||||
assertValidationMode(fileName, VALIDATION_XSD);
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
See the DOCTYPE notes for legacy configs
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://www.springframework.org/schema/beans
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user