Skip to content

Commit c40a249

Browse files
Make EncodingTester usable in testing parsed state
This change updates EncodingTester to make it test the result for cases when the expected character encoding is not limited to what can be determined by checking only the first 1024 bytes of the input stream. Otherwise, without this change, EncodingTester is limited to only being useful for testing the output of the meta prescan.
1 parent d8570bb commit c40a249

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

test-src/nu/validator/htmlparser/test/EncodingTester.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2007 Henri Sivonen
3-
* Copyright (c) 2008 Mozilla Foundation
3+
* Copyright (c) 2008-2020 Mozilla Foundation
44
*
55
* Permission is hereby granted, free of charge, to any person obtaining a
66
* copy of this software and associated documentation files (the "Software"),
@@ -36,10 +36,21 @@
3636

3737
public class EncodingTester {
3838

39+
private int sniffingLimit = 16384;
40+
3941
private final InputStream aggregateStream;
4042

4143
private final StringBuilder builder = new StringBuilder();
4244

45+
/**
46+
* @param aggregateStream
47+
* @param sniffingLimit
48+
*/
49+
public EncodingTester(InputStream aggregateStream, int sniffingLimit) {
50+
this.sniffingLimit = sniffingLimit;
51+
this.aggregateStream = aggregateStream;
52+
}
53+
4354
/**
4455
* @param aggregateStream
4556
*/
@@ -59,7 +70,7 @@ private boolean runTest() throws IOException, SAXException {
5970
}
6071
UntilHashInputStream stream = new UntilHashInputStream(aggregateStream);
6172
HtmlInputStreamReader reader = new HtmlInputStreamReader(stream, null,
62-
null, null, Heuristics.NONE);
73+
null, null, Heuristics.NONE, sniffingLimit);
6374
Charset charset = reader.getCharset();
6475
stream.close();
6576
if (skipLabel()) {

0 commit comments

Comments
 (0)