hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r790351 - in /httpcomponents/httpcore/trunk/httpcore/src: main/java/org/apache/http/message/BasicLineParser.java test/java/org/apache/http/message/TestBasicLineParser.java
Date Wed, 01 Jul 2009 20:06:54 GMT
Author: olegk
Date: Wed Jul  1 20:06:54 2009
New Revision: 790351

URL: http://svn.apache.org/viewvc?rev=790351&view=rev
Log:
Negative HTTP status code will cause a ParseException instead of IllegalArgumentException

Modified:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BasicLineParser.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestBasicLineParser.java

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BasicLineParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BasicLineParser.java?rev=790351&r1=790350&r2=790351&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BasicLineParser.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BasicLineParser.java
Wed Jul  1 20:06:54 2009
@@ -412,13 +412,20 @@
                 blank = indexTo;
             }
             int statusCode = 0;
+            String s = buffer.substringTrimmed(i, blank);
+            for (int j = 0; j < s.length(); j++) {
+                if (!Character.isDigit(s.charAt(j))) {
+                    throw new ParseException(
+                            "Status line contains invalid status code: " 
+                            + buffer.substring(indexFrom, indexTo));
+                }
+            }
             try {
-                statusCode =
-                    Integer.parseInt(buffer.substringTrimmed(i, blank));
+                statusCode = Integer.parseInt(s);
             } catch (NumberFormatException e) {
                 throw new ParseException(
-                    "Unable to parse status code from status line: " 
-                    + buffer.substring(indexFrom, indexTo));
+                        "Status line contains invalid status code: " 
+                        + buffer.substring(indexFrom, indexTo));
             }
             //handle the Reason-Phrase
             i = blank;

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestBasicLineParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestBasicLineParser.java?rev=790351&r1=790350&r2=790351&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestBasicLineParser.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestBasicLineParser.java
Wed Jul  1 20:06:54 2009
@@ -207,12 +207,20 @@
         } catch (ParseException e) {
             // expected
         }
+
         try {
             BasicLineParser.parseStatusLine("HTTP/1.1", null);
             fail();
         } catch (ParseException e) {
             // expected
         }
+
+        try {
+            BasicLineParser.parseStatusLine("HTTP/1.1 -200 OK", null);
+            fail();
+        } catch (ParseException e) {
+            // expected
+        }
     }
 
     public void testHttpVersionParsing() throws Exception {



Mime
View raw message