Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/com/meterware/httpunit/HttpUnitUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public static boolean isEclipse() {
public static String[] parseContentTypeHeader( String header ) {
String[] result = new String[] { "text/plain", null };
StringTokenizer st = new StringTokenizer( header, ";=" );
if (!st.hasMoreTokens()) {
throw new IllegalArgumentException( "Attempting to parse invalid header" );
}
result[0] = st.nextToken();
while (st.hasMoreTokens()) {
String parameter = st.nextToken();
Expand Down Expand Up @@ -458,4 +461,4 @@ public static boolean setEXCEPTION_DEBUG(boolean exception_debug) {
EXCEPTION_DEBUG = exception_debug;
return oldExceptionDebug;
}
}
}
11 changes: 11 additions & 0 deletions test/com/meterware/httpunit/EncodingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ public void testParseContentHeader() throws Exception {
}


public void testParseEmptyHeader() throws Exception {
String invalidHeader = "";
try {
String result[]=HttpUnitUtils.parseContentTypeHeader(invalidHeader);
fail();
} catch (IllegalArgumentException iae) {
assertEquals( "header", "Attempting to parse invalid header" , iae.getMessage() );
}
}


public void testSpecifiedEncoding() throws Exception {
String hebrewTitle = "\u05d0\u05d1\u05d2\u05d3";
String page = "<html><head><title>" + hebrewTitle + "</title></head>\n" +
Expand Down