-
Notifications
You must be signed in to change notification settings - Fork 38.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve comment parsing in DTD/XSD detection algorithm
Prior to this commit, XmlValidationModeDetector did not properly parse all categories of comments (described below). When such categories of comments were encountered XmlValidationModeDetector may have incorrectly detected that an XML file used a DTD when it used an XSD, or vice versa. This commit revises the parsing algorithm in XmlValidationModeDetector so that multi-line comments and multiple comments on a single line are properly recognized. Specifically, with this commit the following categories of comments are now handled properly. - Multiple comments on a single line - Multi-line comment: beginning on one line and then ending on another line with an additional comment following on that same line. - Multi-line comment: beginning at the end of XML content on one line and then spanning multiple lines. Closes gh-27915
- Loading branch information
Showing
8 changed files
with
75 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
spring-core/src/test/resources/org/springframework/util/xml/dtdWithNoComments.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "https://www.springframework.org/dtd/spring-beans-2.0.dtd"> | ||
|
||
<beans> | ||
|
||
</beans> |
6 changes: 6 additions & 0 deletions
6
...test/resources/org/springframework/util/xml/dtdWithTrailingCommentAcrossMultipleLines.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "https://www.springframework.org/dtd/spring-beans-2.0.dtd"><!-- comment --><beans><!-- | ||
trailing comment across multiple lines --> | ||
|
||
|
||
</beans> |
8 changes: 8 additions & 0 deletions
8
spring-core/src/test/resources/org/springframework/util/xml/xsdWithDoctypeInComment.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "https://www.springframework.org/dtd/spring-beans-2.0.dtd"> --> | ||
<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> |
9 changes: 9 additions & 0 deletions
9
...g/springframework/util/xml/xsdWithDoctypeInOpenCommentWithAdditionalCommentOnSameLine.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "https://www.springframework.org/dtd/spring-beans-2.0.dtd"> --> <!-- additional comment on same line --> | ||
<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> |
10 changes: 10 additions & 0 deletions
10
spring-core/src/test/resources/org/springframework/util/xml/xsdWithMultipleComments.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- comment #1 --> <!-- comment #2 --> <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"><!-- | ||
trailing | ||
comment | ||
--> | ||
|
||
</beans> |
8 changes: 8 additions & 0 deletions
8
spring-core/src/test/resources/org/springframework/util/xml/xsdWithNoComments.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<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> |