-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spring fails to determine that XML is DTD-based if DTD declaration is followed by a comment #23605
Comments
兄弟,你用的spring5.1.9,配置文件用的2.x版本的 那有啥用啊 |
这个bug跟使用哪个版本的xml配置文件无关。不过,这确实是一个很小的bug,几乎不会影响到正常使用... |
我刚刚又测试了一下,发现如果 |
这个我知道,因为它在猜测验证模式时,是先去掉注释以及注释之前的部分,然后在剩下的部分里查看是否有DOCTYPE标记。加入换行后,在第一行就可以检测出DOCTYPE标记了,所以没问题。 |
@kangjianwei, thanks for raising the issue. @kangjianwei and @qw81641493, it would be very helpful to the Spring maintainers reading this issue if you would translate your discussion into English. |
I have confirmed that this is a bug. Appending |
The fix for this will be available in 5.1.10 and 5.2.0. Feel free to try it out in upcoming snapshot builds for 5.1.10 and 5.2. |
Version
Tested on spring 5.1.9.RELEASE.
Repro
spring-config.xml
(note that there is a comment at the end of the DOCTYPE line)Load this configuration file
ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
An exception has occurred
Analysis
The cause of the exception is to incorrectly parse the validation mode of the XML document.
The code that causes the bug is in the consumeCommentTokens(String) method of the
org.springframework.util.xml.XmlValidationModeDetector
.This method not only consumes the comment itself, but also consumes the content before the comment.
Suppose a line in the xml file has the following code:
aaa<!--BUG-->bbb
After this content is processed by this method, only the "bbb" string will be returned.
In other words, the effective information "aaa" is lost.
This is why the xml validation type cannot be parsed correctly after adding a comment after the DOCTYPE line.
The text was updated successfully, but these errors were encountered: