diff --git a/src/com/meterware/httpunit/HttpUnitUtils.java b/src/com/meterware/httpunit/HttpUnitUtils.java index c8a4f05..365875d 100644 --- a/src/com/meterware/httpunit/HttpUnitUtils.java +++ b/src/com/meterware/httpunit/HttpUnitUtils.java @@ -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(); @@ -458,4 +461,4 @@ public static boolean setEXCEPTION_DEBUG(boolean exception_debug) { EXCEPTION_DEBUG = exception_debug; return oldExceptionDebug; } -} \ No newline at end of file +} diff --git a/test/com/meterware/httpunit/EncodingTest.java b/test/com/meterware/httpunit/EncodingTest.java index 9d258c6..3a338ed 100644 --- a/test/com/meterware/httpunit/EncodingTest.java +++ b/test/com/meterware/httpunit/EncodingTest.java @@ -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 = "" + hebrewTitle + "\n" +