Skip to content

Commit 7e9da44

Browse files
committed
Merge branch '7.0.x'
2 parents a077324 + 4074155 commit 7e9da44

5 files changed

Lines changed: 38 additions & 3 deletions

File tree

spring-core/src/main/java/org/springframework/util/xml/XmlValidationModeDetector.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ private boolean hasOpeningTag(String content) {
151151
private String consumeCommentTokens(String line) {
152152
int indexOfStartComment = line.indexOf(START_COMMENT);
153153
if (indexOfStartComment == -1 && !line.contains(END_COMMENT)) {
154-
return line;
154+
// If we are inside a multi-line comment, the entire line is comment
155+
// data and must not be treated as content.
156+
return (this.inComment ? "" : line);
155157
}
156158

157159
String result = "";

spring-core/src/test/java/org/springframework/util/xml/XmlValidationModeDetectorTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class XmlValidationModeDetectorTests {
4444
"dtdWithTrailingComment.xml",
4545
"dtdWithTrailingCommentAcrossMultipleLines.xml",
4646
"dtdWithCommentOnNextLine.xml",
47-
"dtdWithMultipleComments.xml"
47+
"dtdWithMultipleComments.xml",
48+
"dtdWithDoctypeInMultiLineCommentBody.xml"
4849
})
4950
void dtdDetection(String fileName) throws Exception {
5051
assertValidationMode(fileName, VALIDATION_DTD);
@@ -55,7 +56,9 @@ void dtdDetection(String fileName) throws Exception {
5556
"xsdWithNoComments.xml",
5657
"xsdWithMultipleComments.xml",
5758
"xsdWithDoctypeInComment.xml",
58-
"xsdWithDoctypeInOpenCommentWithAdditionalCommentOnSameLine.xml"
59+
"xsdWithDoctypeInOpenCommentWithAdditionalCommentOnSameLine.xml",
60+
"xsdWithDoctypeInMultiLineCommentBody.xml",
61+
"xsdWithMultipleDoctypesInMultiLineCommentBody.xml"
5962
})
6063
void xsdDetection(String fileName) throws Exception {
6164
assertValidationMode(fileName, VALIDATION_XSD);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
DOCTYPE
4+
-->
5+
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "https://www.springframework.org/dtd/spring-beans-2.0.dtd">
6+
<beans>
7+
8+
</beans>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
See the DOCTYPE notes for legacy configs
4+
-->
5+
<beans xmlns="http://www.springframework.org/schema/beans"
6+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7+
xsi:schemaLocation="https://www.springframework.org/schema/beans
8+
https://www.springframework.org/schema/beans/spring-beans.xsd">
9+
10+
</beans>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
xxx DOCTYPE xxx
4+
yyy
5+
zzz DOCTYPE zzz
6+
-->
7+
<beans xmlns="http://www.springframework.org/schema/beans"
8+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:schemaLocation="https://www.springframework.org/schema/beans
10+
https://www.springframework.org/schema/beans/spring-beans.xsd">
11+
12+
</beans>

0 commit comments

Comments
 (0)