This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new 2ef9f33 Refactor Hostname validation to improve performance. 2ef9f33 is described below commit 2ef9f33e804d7665c1fe0d78dc547c429921bbf3 Author: Mark Thomas <ma...@apache.org> AuthorDate: Tue Apr 30 12:17:23 2019 +0100 Refactor Hostname validation to improve performance. Patch provided by Uwe Hees. --- java/org/apache/tomcat/util/http/parser/HttpParser.java | 16 ++++++++-------- .../tomcat/util/http/parser/TesterHostPerformance.java | 1 + webapps/docs/changelog.xml | 4 ++++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/java/org/apache/tomcat/util/http/parser/HttpParser.java b/java/org/apache/tomcat/util/http/parser/HttpParser.java index 539420c..8598321 100644 --- a/java/org/apache/tomcat/util/http/parser/HttpParser.java +++ b/java/org/apache/tomcat/util/http/parser/HttpParser.java @@ -910,7 +910,14 @@ public class HttpParser { } public DomainParseState next(int c) { - if (HttpParser.isAlpha(c)) { + if (c == -1) { + if (allowsEnd) { + return END; + } else { + throw new IllegalArgumentException( + sm.getString("http.invalidSegmentEndState", this.name())); + } + } else if (HttpParser.isAlpha(c)) { return ALPHA; } else if (HttpParser.isNumeric(c)) { return NUMERIC; @@ -928,13 +935,6 @@ public class HttpParser { throw new IllegalArgumentException(sm.getString("http.invalidCharacterDomain", Character.toString((char) c), errorLocation)); } - } else if (c == -1) { - if (allowsEnd) { - return END; - } else { - throw new IllegalArgumentException( - sm.getString("http.invalidSegmentEndState", this.name())); - } } else if (c == '-') { if (allowsHyphen) { return HYPHEN; diff --git a/test/org/apache/tomcat/util/http/parser/TesterHostPerformance.java b/test/org/apache/tomcat/util/http/parser/TesterHostPerformance.java index a6c3e75..b579be3 100644 --- a/test/org/apache/tomcat/util/http/parser/TesterHostPerformance.java +++ b/test/org/apache/tomcat/util/http/parser/TesterHostPerformance.java @@ -36,6 +36,7 @@ public class TesterHostPerformance { List<Object[]> result = new ArrayList<>(); result.add(new Object[] { "localhost" }); result.add(new Object[] { "tomcat.apache.org" }); + result.add(new Object[] { "tomcat.apache.org." }); result.add(new Object[] { "127.0.0.1" }); result.add(new Object[] { "255.255.255.255" }); result.add(new Object[] { "[::1]" }); diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 6591d46..586104b 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -103,6 +103,10 @@ When running on newer JREs that don't support SSLv2Hello, don't warn that it is not available unless explicitly configured. (markt) </fix> + <scode> + Refactor Hostname validation to improve performance. Patch provided by + Uwe Hees. (markt) + </scode> </changelog> </subsection> <subsection name="Other"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org