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 3c78313bd0d5..31671eabe73b 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 @@ private boolean hasOpeningTag(String content) { 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 9714eef1c649..dcdcf3e49d0e 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 @@ -55,7 +55,8 @@ void dtdDetection(String fileName) throws Exception { "xsdWithNoComments.xml", "xsdWithMultipleComments.xml", "xsdWithDoctypeInComment.xml", - "xsdWithDoctypeInOpenCommentWithAdditionalCommentOnSameLine.xml" + "xsdWithDoctypeInOpenCommentWithAdditionalCommentOnSameLine.xml", + "xsdWithDoctypeInMultiLineCommentBody.xml" }) void xsdDetection(String fileName) throws Exception { assertValidationMode(fileName, VALIDATION_XSD); 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 000000000000..2a34756ee05d --- /dev/null +++ b/spring-core/src/test/resources/org/springframework/util/xml/xsdWithDoctypeInMultiLineCommentBody.xml @@ -0,0 +1,10 @@ + + + + +