Author: sebb
Date: Wed Apr 16 18:34:33 2008
New Revision: 648916

URL: http://svn.apache.org/viewvc?rev=648916&view=rev
Log:
Bug 44784 - allow for broken server returning additional charset

Added:
    
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPUtils.java
   (with props)
Modified:
    
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/ConversionUtils.java
    jakarta/jmeter/trunk/xdocs/changes.xml

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=648916&r1=648915&r2=648916&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 16 18:34:33 2008
@@ -20,6 +20,8 @@
 
 import org.apache.jorphan.util.JOrphanUtils;
 
+// @see TestHTTPUtils for unit tests
+
 /**
  * General purpose conversion utilities related to HTTP/HTML
  */
@@ -33,19 +35,27 @@
      * e.g. "text/html; charset=utf-8".
      * 
      * @param contentType
-     * @return the charset encoding
+     * @return the charset encoding - or null, if none was found
      */
     public static String getEncodingFromContentType(String contentType){
         String charSet = null;
         if (contentType != null) {
             int charSetStartPos = 
contentType.toLowerCase().indexOf(CHARSET_EQ);
-            if (charSetStartPos > 0) {
+            if (charSetStartPos >= 0) {
                 charSet = contentType.substring(charSetStartPos + 
CHARSET_EQ_LEN);
                 if (charSet != null) {
                     // Remove quotes from charset name
                     charSet = JOrphanUtils.replaceAllChars(charSet, '"', "");
                     charSet = charSet.trim();
                     if (charSet.length() > 0) {
+                        // See Bug 44784
+                        int semi = charSet.indexOf(";");
+                        if (semi == 0){
+                            return null;
+                        }
+                        if (semi != -1) {
+                            return charSet.substring(0,semi);
+                        }
                         return charSet;
                     }
                     return null;

Added: 
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=648916&view=auto
==============================================================================
--- 
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPUtils.java
 (added)
+++ 
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPUtils.java
 Wed Apr 16 18:34:33 2008
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ */
+
+package org.apache.jmeter.protocol.http.util;
+
+import junit.framework.TestCase;
+
+public class TestHTTPUtils extends TestCase {
+               public TestHTTPUtils(String name) {
+                       super(name);
+               }
+
+               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"));
+            assertNull(ConversionUtils.getEncodingFromContentType("charset="));
+            
assertNull(ConversionUtils.getEncodingFromContentType(";charset=;"));
+               }
+               
+               public void testEncoding() throws Exception {
+               }
+}

Propchange: 
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPUtils.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=648916&r1=648915&r2=648916&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Wed Apr 16 18:34:33 2008
@@ -158,6 +158,7 @@
 <li>Regex Function can now also be applied to a variable rather than just the 
previous sample result.</li>
 <li>Remove HTML Parameter Mask,HTTP User Parameter Modifier from menus as they 
are deprecated</li>
 <li>Bug 44807 - allow session ids to be terminated by backslash</li>
+<li>Bug 44784 - allow for broken server returning additional charset</li>
 </ul>
 
 <h4>Non-functional changes</h4>



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

Reply via email to