System.arraycopy(bufUTF16, 0, total, utf16bom.length+buf.length, bufUTF16.length);
HTMLFilter filter = new HTMLFilter();
boolean failed = false;
FileOutputStream fos;
try {
ArrayBucket out = new ArrayBucket();
filter.readFilter(new ArrayBucket(total).getInputStream(), out.getOutputStream(), "UTF-16", null, null);
fos = new FileOutputStream("output.utf16");
fos.write(out.toByteArray());
fos.close();
failed = true;
assertFalse("Filter accepted dangerous UTF8 text with BOM as UTF16! (HTMLFilter)", true);
} catch (DataFilterException e) {
System.out.println("Failure: "+e);
e.printStackTrace();
if(e.getCause() != null) {
e.getCause().printStackTrace();
}
// Ok.
}
try {
ArrayBucket out = new ArrayBucket();
FilterStatus fo = ContentFilter.filter(new ArrayBucket(total).getInputStream(), out.getOutputStream(), "text/html", null, null);
fos = new FileOutputStream("output.filtered");
fos.write(out.toByteArray());
fos.close();
failed = true;
assertFalse("Filter accepted dangerous UTF8 text with BOM as UTF16! (ContentFilter) - Detected charset: "+fo.charset, true);
} catch (DataFilterException e) {
System.out.println("Failure: "+e);