Skip to content

Commit 1763bfb

Browse files
committed
Fixed content length check in XmlValidationModeDetector
Issue: SPR-11477
1 parent bc5af2c commit 1763bfb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2007 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -123,7 +123,7 @@ public int detectValidationMode(InputStream inputStream) throws IOException {
123123
* Does the content contain the the DTD DOCTYPE declaration?
124124
*/
125125
private boolean hasDoctype(String content) {
126-
return (content.indexOf(DOCTYPE) > -1);
126+
return content.contains(DOCTYPE);
127127
}
128128

129129
/**
@@ -136,7 +136,8 @@ private boolean hasOpeningTag(String content) {
136136
return false;
137137
}
138138
int openTagIndex = content.indexOf('<');
139-
return (openTagIndex > -1 && content.length() > openTagIndex && Character.isLetter(content.charAt(openTagIndex + 1)));
139+
return (openTagIndex > -1 && (content.length() > openTagIndex + 1) &&
140+
Character.isLetter(content.charAt(openTagIndex + 1)));
140141
}
141142

142143
/**
@@ -146,7 +147,7 @@ private boolean hasOpeningTag(String content) {
146147
* the DOCTYPE declaration or the root element of the document.
147148
*/
148149
private String consumeCommentTokens(String line) {
149-
if (line.indexOf(START_COMMENT) == -1 && line.indexOf(END_COMMENT) == -1) {
150+
if (!line.contains(START_COMMENT) && !line.contains(END_COMMENT)) {
150151
return line;
151152
}
152153
while ((line = consume(line)) != null) {

0 commit comments

Comments
 (0)