You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2018/05/12 17:01:12 UTC

svn commit: r1831483 - in /tomcat/trunk: java/org/apache/tomcat/util/http/parser/HttpParser.java test/org/apache/tomcat/util/http/parser/TestHttpParserHost.java

Author: markt
Date: Sat May 12 17:01:11 2018
New Revision: 1831483

URL: http://svn.apache.org/viewvc?rev=1831483&view=rev
Log:
Simplify HostParser after reviewing code.
Add additional test case.

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java
    tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestHttpParserHost.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java?rev=1831483&r1=1831482&r2=1831483&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java Sat May 12 17:01:11 2018
@@ -844,28 +844,26 @@ public class HttpParser {
 
 
     private enum DomainParseState {
-        NEW(       true, false, false,  AllowsEnd.NEVER,  AllowsEnd.NEVER, " at the start of"),
-        ALL_ALPHA( true,  true,  true, AllowsEnd.ALWAYS, AllowsEnd.ALWAYS, " after a letter in"),
-        ALPHA(     true,  true,  true,  AllowsEnd.FIRST,  AllowsEnd.FIRST, " after a letter in"),
-        NUMERIC(   true,  true,  true,  AllowsEnd.FIRST,  AllowsEnd.FIRST, " after a number in"),
-        PERIOD(    true, false, false,  AllowsEnd.NEVER,  AllowsEnd.NEVER, " after a period in"),
-        HYPHEN(    true,  true, false,  AllowsEnd.NEVER,  AllowsEnd.NEVER, " after a hypen in"),
-        COLON(    false, false, false,  AllowsEnd.NEVER,  AllowsEnd.NEVER, " after a colon in"),
-        END(      false, false, false,  AllowsEnd.NEVER,  AllowsEnd.NEVER, " at the end of");
+        NEW(       true, false, false,  AllowsEnd.NEVER, " at the start of"),
+        ALL_ALPHA( true,  true,  true, AllowsEnd.ALWAYS, " after a letter in"),
+        ALPHA(     true,  true,  true,  AllowsEnd.FIRST, " after a letter in"),
+        NUMERIC(   true,  true,  true,  AllowsEnd.FIRST, " after a number in"),
+        PERIOD(    true, false, false,  AllowsEnd.NEVER, " after a period in"),
+        HYPHEN(    true,  true, false,  AllowsEnd.NEVER, " after a hypen in"),
+        COLON(    false, false, false,  AllowsEnd.NEVER, " after a colon in"),
+        END(      false, false, false,  AllowsEnd.NEVER, " at the end of");
 
         private final boolean mayContinue;
         private final boolean allowsHyphen;
         private final boolean allowsPeriod;
-        private final AllowsEnd allowsColon;
         private final AllowsEnd allowsEnd;
         private final String errorLocation;
 
         private DomainParseState(boolean mayContinue, boolean allowsHyphen, boolean allowsPeriod,
-                AllowsEnd allowsColon, AllowsEnd allowsEnd, String errorLocation) {
+                AllowsEnd allowsEnd, String errorLocation) {
             this.mayContinue = mayContinue;
             this.allowsHyphen = allowsHyphen;
             this.allowsPeriod = allowsPeriod;
-            this.allowsColon = allowsColon;
             this.allowsEnd = allowsEnd;
             this.errorLocation = errorLocation;
         }
@@ -891,8 +889,8 @@ public class HttpParser {
                             Character.toString((char) c), errorLocation));
                 }
             } else if (c == ':') {
-                if (allowsColon == AllowsEnd.ALWAYS ||
-                        allowsColon == AllowsEnd.FIRST && segmentIndex == 0) {
+                if (allowsEnd == AllowsEnd.ALWAYS ||
+                        allowsEnd == AllowsEnd.FIRST && segmentIndex == 0) {
                     return COLON;
                 } else {
                     throw new IllegalArgumentException(sm.getString("http.invalidCharacterDomain",

Modified: tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestHttpParserHost.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestHttpParserHost.java?rev=1831483&r1=1831482&r2=1831483&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestHttpParserHost.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestHttpParserHost.java Sat May 12 17:01:11 2018
@@ -91,6 +91,7 @@ public class TestHttpParserHost {
         result.add(new Object[] { TestType.IPv4, "123", Integer.valueOf(-1), null} );
         result.add(new Object[] { TestType.IPv4, "123:8080", Integer.valueOf(3), null} );
         result.add(new Object[] { TestType.IPv4, "myapp-t.mydomain.com", Integer.valueOf(-1), null} );
+        result.add(new Object[] { TestType.IPv4, "myapp-t.my-domain.com", Integer.valueOf(-1), null} );
         // Domain Name - invalid
         result.add(new Object[] { TestType.IPv4, ".", Integer.valueOf(-1), IAE} );
         result.add(new Object[] { TestType.IPv4, ".:8080", Integer.valueOf(-1), IAE} );
@@ -202,6 +203,7 @@ public class TestHttpParserHost {
 
             }
         } catch (Exception e) {
+            e.printStackTrace();
             exceptionClass = e.getClass();
         }
         Assert.assertEquals(input, expectedResult.intValue(), result);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org