Allow for quoted charset in Content-Type parsing

git-svn-id: https://svn.apache.org/repos/asf/jakarta/jmeter/branches/rel-2-2@565694 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2007-08-14 10:20:31 +00:00
parent 2f586750b7
commit f37e800011
3 changed files with 38 additions and 5 deletions

View File

@ -34,6 +34,8 @@ import org.apache.jorphan.logging.LoggingManager;
import org.apache.jorphan.util.JOrphanUtils;
import org.apache.log.Logger;
// For unit tests, @see TestSampleResult
/**
* This is a nice packaging for the various information returned from taking a
* sample of an entry.
@ -48,7 +50,8 @@ public class SampleResult implements Serializable {
// However the suggested System.getProperty("file.encoding") is Cp1252 on
// Windows
// So use a new property with the original value as default
private static final String DEFAULT_ENCODING
// needs to be accessible from test code
static final String DEFAULT_ENCODING
= JMeterUtils.getPropDefault("sampleresult.default.encoding", // $NON-NLS-1$
"ISO-8859-1"); // $NON-NLS-1$
@ -548,11 +551,17 @@ public class SampleResult implements Serializable {
// <META http-equiv="content-type" content="text/html;
// charset=foobar">
// or can we leave that to the renderer ?
String de = ct.toLowerCase();
final String cs = "charset="; // $NON-NLS-1$
int cset = de.indexOf(cs);
final String CS_PFX = "charset="; // $NON-NLS-1$
int cset = ct.toLowerCase().indexOf(CS_PFX);
if (cset >= 0) {
setDataEncoding(de.substring(cset + cs.length()));
// TODO - assumes charset is not followed by anything else
String charSet = ct.substring(cset + CS_PFX.length());
// Check for quoted string
if (charSet.startsWith("\"")){ // $NON-NLS-1$
setDataEncoding(charSet.substring(1, charSet.length()-1)); // remove quotes
} else {
setDataEncoding(charSet);
}
}
if (ct.startsWith("image/")) {// $NON-NLS-1$
setDataType(BINARY);

View File

@ -180,5 +180,28 @@ public class TestSampleResult extends TestCase {
}
// TODO some more invalid sequence tests needed
public void testEncodingAndType() throws Exception {
// check default
SampleResult res = new SampleResult();
assertEquals(SampleResult.DEFAULT_ENCODING,res.getDataEncoding());
assertEquals("DataType should be blank","",res.getDataType());
// check null changes nothing
res.setEncodingAndType(null);
assertEquals(SampleResult.DEFAULT_ENCODING,res.getDataEncoding());
assertEquals("DataType should be blank","",res.getDataType());
// Check unquoted charset
res.setEncodingAndType("text/html; charset=aBcd");
assertEquals("aBcd",res.getDataEncoding());
assertEquals("text",res.getDataType());
// Check quoted charset
res.setEncodingAndType("text/html; charset=\"aBcd\"");
assertEquals("aBcd",res.getDataEncoding());
assertEquals("text",res.getDataType());
}
}

View File

@ -42,6 +42,7 @@
<li>Fix possible NPE in HTTPSampler2 if 302 does not have Location header.</li>
<li>Bug 42919 - Failure Message blank in CSV output [now records first non-blank message]</li>
<li>Add link to Extending JMeter PDF</li>
<li>Allow for quoted charset in Content-Type parsing</li>
</ul>
<h3>Version 2.3RC3</h3>