Author: sebb
Date: Wed Apr 23 09:12:47 2008
New Revision: 650928

URL: http://svn.apache.org/viewvc?rev=650928&view=rev
Log:
Bug 44784 - allow for unsupported charset

Modified:
    
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java
    
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPUtils.java

Modified: 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java?rev=650928&r1=650927&r2=650928&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java
 (original)
+++ 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java
 Wed Apr 23 09:12:47 2008
@@ -18,6 +18,8 @@
 
 package org.apache.jmeter.protocol.http.util;
 
+import java.nio.charset.Charset;
+
 import org.apache.jorphan.util.JOrphanUtils;
 
 // @see TestHTTPUtils for unit tests
@@ -35,7 +37,7 @@
      * e.g. "text/html; charset=utf-8".
      * 
      * @param contentType
-     * @return the charset encoding - or null, if none was found
+     * @return the charset encoding - or null, if none was found or the 
charset is not supported
      */
     public static String getEncodingFromContentType(String contentType){
         String charSet = null;
@@ -54,7 +56,10 @@
                             return null;
                         }
                         if (semi != -1) {
-                            return charSet.substring(0,semi);
+                            charSet = charSet.substring(0,semi);
+                        }
+                        if (!Charset.isSupported(charSet)){
+                            return null;
                         }
                         return charSet;
                     }

Modified: 
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPUtils.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPUtils.java?rev=650928&r1=650927&r2=650928&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPUtils.java
 (original)
+++ 
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPUtils.java
 Wed Apr 23 09:12:47 2008
@@ -27,14 +27,12 @@
 
                public void testgetEncoding() throws Exception {
                    
assertNull(ConversionUtils.getEncodingFromContentType("xyx"));
-            
assertEquals("abc",ConversionUtils.getEncodingFromContentType("charset=abc"));
-            
assertEquals("abc",ConversionUtils.getEncodingFromContentType("charset=\"abc\""));
-            
assertEquals("abc",ConversionUtils.getEncodingFromContentType("text/plain 
;charset=abc"));
-            
assertEquals("abc",ConversionUtils.getEncodingFromContentType("text/html 
;charset=abc;charset=def"));
+            
assertEquals("utf8",ConversionUtils.getEncodingFromContentType("charset=utf8"));
+            
assertEquals("utf8",ConversionUtils.getEncodingFromContentType("charset=\"utf8\""));
+            
assertEquals("utf8",ConversionUtils.getEncodingFromContentType("text/plain 
;charset=utf8"));
+            
assertEquals("utf8",ConversionUtils.getEncodingFromContentType("text/html 
;charset=utf8;charset=def"));
             assertNull(ConversionUtils.getEncodingFromContentType("charset="));
             
assertNull(ConversionUtils.getEncodingFromContentType(";charset=;"));
-               }
-               
-               public void testEncoding() throws Exception {
+            
assertNull(ConversionUtils.getEncodingFromContentType(";charset=no-such-charset;"));
                }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to