diff --git a/spring-core/src/main/java/org/springframework/util/xml/XmlValidationModeDetector.java b/spring-core/src/main/java/org/springframework/util/xml/XmlValidationModeDetector.java
index 3c78313bd0d..31671eabe73 100644
--- a/spring-core/src/main/java/org/springframework/util/xml/XmlValidationModeDetector.java
+++ b/spring-core/src/main/java/org/springframework/util/xml/XmlValidationModeDetector.java
@@ -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 = "";
diff --git a/spring-core/src/test/java/org/springframework/util/xml/XmlValidationModeDetectorTests.java b/spring-core/src/test/java/org/springframework/util/xml/XmlValidationModeDetectorTests.java
index 9714eef1c64..15a97691c1e 100644
--- a/spring-core/src/test/java/org/springframework/util/xml/XmlValidationModeDetectorTests.java
+++ b/spring-core/src/test/java/org/springframework/util/xml/XmlValidationModeDetectorTests.java
@@ -44,7 +44,8 @@ class XmlValidationModeDetectorTests {
"dtdWithTrailingComment.xml",
"dtdWithTrailingCommentAcrossMultipleLines.xml",
"dtdWithCommentOnNextLine.xml",
- "dtdWithMultipleComments.xml"
+ "dtdWithMultipleComments.xml",
+ "dtdWithDoctypeInMultiLineCommentBody.xml"
})
void dtdDetection(String fileName) throws Exception {
assertValidationMode(fileName, VALIDATION_DTD);
@@ -55,7 +56,9 @@ class XmlValidationModeDetectorTests {
"xsdWithNoComments.xml",
"xsdWithMultipleComments.xml",
"xsdWithDoctypeInComment.xml",
- "xsdWithDoctypeInOpenCommentWithAdditionalCommentOnSameLine.xml"
+ "xsdWithDoctypeInOpenCommentWithAdditionalCommentOnSameLine.xml",
+ "xsdWithDoctypeInMultiLineCommentBody.xml",
+ "xsdWithMultipleDoctypesInMultiLineCommentBody.xml"
})
void xsdDetection(String fileName) throws Exception {
assertValidationMode(fileName, VALIDATION_XSD);
diff --git a/spring-core/src/test/resources/org/springframework/util/xml/dtdWithDoctypeInMultiLineCommentBody.xml b/spring-core/src/test/resources/org/springframework/util/xml/dtdWithDoctypeInMultiLineCommentBody.xml
new file mode 100644
index 00000000000..9256a3103b0
--- /dev/null
+++ b/spring-core/src/test/resources/org/springframework/util/xml/dtdWithDoctypeInMultiLineCommentBody.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
diff --git a/spring-core/src/test/resources/org/springframework/util/xml/xsdWithDoctypeInMultiLineCommentBody.xml b/spring-core/src/test/resources/org/springframework/util/xml/xsdWithDoctypeInMultiLineCommentBody.xml
new file mode 100644
index 00000000000..2a34756ee05
--- /dev/null
+++ b/spring-core/src/test/resources/org/springframework/util/xml/xsdWithDoctypeInMultiLineCommentBody.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
diff --git a/spring-core/src/test/resources/org/springframework/util/xml/xsdWithMultipleDoctypesInMultiLineCommentBody.xml b/spring-core/src/test/resources/org/springframework/util/xml/xsdWithMultipleDoctypesInMultiLineCommentBody.xml
new file mode 100644
index 00000000000..87a39cdaaf8
--- /dev/null
+++ b/spring-core/src/test/resources/org/springframework/util/xml/xsdWithMultipleDoctypesInMultiLineCommentBody.xml
@@ -0,0 +1,12 @@
+
+
+
+
+