hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r389604 - in /jakarta/httpcomponents/trunk/http-core/src: java/org/apache/http/ java/org/apache/http/io/ java/org/apache/http/util/ test/org/apache/http/io/ test/org/apache/http/util/
Date Tue, 28 Mar 2006 21:03:48 GMT
Author: olegk
Date: Tue Mar 28 13:03:47 2006
New Revision: 389604

URL: http://svn.apache.org/viewcvs?rev=389604&view=rev
Log:
Reverted to Integer#parseInt for parsing numbers in HTTP messages

Removed:
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/util/NumUtils.java
    jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/util/TestNumUtils.java
Modified:
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HttpVersion.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ChunkedInputStream.java
    jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/io/TestChunkCoding.java
    jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/util/TestAllUtil.java

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HttpVersion.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HttpVersion.java?rev=389604&r1=389603&r2=389604&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HttpVersion.java (original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HttpVersion.java Tue Mar
28 13:03:47 2006
@@ -31,7 +31,6 @@
 
 import org.apache.http.io.CharArrayBuffer;
 import org.apache.http.protocol.HTTP;
-import org.apache.http.util.NumUtils;
 
 /**
  *  <p>HTTP version, as specified in RFC 2616.</p>
@@ -257,13 +256,13 @@
                         buffer.substring(indexFrom, indexTo));
             }
             try {
-                major = NumUtils.parseUnsignedInt(buffer, i, period); 
+                major = Integer.parseInt(buffer.substringTrimmed(i, period)); 
             } catch (NumberFormatException e) {
                 throw new ProtocolException("Invalid HTTP major version number: " + 
                         buffer.substring(indexFrom, indexTo));
             }
             try {
-                minor = NumUtils.parseUnsignedInt(buffer, period + 1, indexTo); 
+                minor = Integer.parseInt(buffer.substringTrimmed(period + 1, indexTo)); 
             } catch (NumberFormatException e) {
                 throw new ProtocolException("Invalid HTTP minor version number: " + 
                         buffer.substring(indexFrom, indexTo));

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ChunkedInputStream.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ChunkedInputStream.java?rev=389604&r1=389603&r2=389604&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ChunkedInputStream.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ChunkedInputStream.java
Tue Mar 28 13:03:47 2006
@@ -36,7 +36,6 @@
 import org.apache.http.HttpException;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.util.ExceptionUtils;
-import org.apache.http.util.NumUtils;
 
 /**
  * <p>This class implements chunked transfer coding as described in the 
@@ -232,6 +231,9 @@
      */
     private void nextChunk() throws IOException {
         chunkSize = getChunkSize();
+        if (chunkSize < 0) {
+            throw new MalformedChunkCodingException("Negative chunk size");
+        }
         bof = false;
         pos = 0;
         if (chunkSize == 0) {
@@ -275,7 +277,7 @@
             separator = this.buffer.length();
         }
         try {
-            return NumUtils.parseUnsignedHexInt(this.buffer, 0, separator);
+            return Integer.parseInt(this.buffer.substringTrimmed(0, separator), 16);
         } catch (NumberFormatException e) {
             throw new MalformedChunkCodingException("Bad chunk header");
         }

Modified: jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/io/TestChunkCoding.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/io/TestChunkCoding.java?rev=389604&r1=389603&r2=389604&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/io/TestChunkCoding.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/io/TestChunkCoding.java
Tue Mar 28 13:03:47 2006
@@ -258,6 +258,20 @@
         }
     }
 
+    // Negative chunk size
+    public void testCorruptChunkedInputStreamNegativeSize() throws IOException {
+        String s = "-5\r\n01234\r\n5\r\n56789\r\n0\r\n";
+        InputStream in = new ChunkedInputStream(
+                new HttpDataReceiverMockup(
+                        EncodingUtils.getBytes(s, CONTENT_CHARSET)));
+        try {
+            in.read();
+            fail("MalformedChunkCodingException should have been thrown");
+        } catch(MalformedChunkCodingException e) {
+            /* expected exception */
+        }
+    }
+
     // Invalid footer
     public void testCorruptChunkedInputStreamInvalidFooter() throws IOException {
         String s = "1\r\n0\r\n0\r\nstuff\r\n";

Modified: jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/util/TestAllUtil.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/util/TestAllUtil.java?rev=389604&r1=389603&r2=389604&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/util/TestAllUtil.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/util/TestAllUtil.java
Tue Mar 28 13:03:47 2006
@@ -43,7 +43,6 @@
         suite.addTest(TestEncodingUtils.suite());
         suite.addTest(TestDateUtils.suite());
         suite.addTest(TestEntityUtils.suite());
-        suite.addTest(TestNumUtils.suite());
         return suite;
     }
 



Mime
View raw message