Skip to content

Commit 9556fdb

Browse files
committed
reject binary files
1 parent 11f5c74 commit 9556fdb

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

qulice-checkstyle/src/main/resources/com/qulice/checkstyle/checks.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
101101
<property name="message" value="Two consecutive empty lines"/>
102102
</module>
103103
<!--
104+
Checks that the file is not binary
105+
-->
106+
<module name="RegexpMultiline">
107+
<property name="format" value=".*[\x00-\x08\x0E-\x1F].*"/>
108+
<property name="fileExtensions" value="java"/>
109+
<property name="id" value="BinaryFiles"/>
110+
<property name="message" value="Binary files are not allowed"/>
111+
</module>
112+
<!--
104113
JavaDoc regexp checks
105114
-->
106115
<module name="RegexpSingleline">

qulice-checkstyle/src/test/java/com/qulice/checkstyle/CheckstyleValidatorTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ void acceptsInstanceMethodReferences() throws Exception {
139139
);
140140
}
141141

142+
/**
143+
* CheckstyleValidator can deny binary contents in java file.
144+
* This is test for #1264.
145+
* @throws Exception If something wrong happens inside
146+
*/
147+
@Test
148+
void rejectsJavaFileWithBinaryContent() throws Exception {
149+
this.runValidation("JavaFileWithBinaryContent.java", false);
150+
}
151+
142152
/**
143153
* CheckstyleValidator can report error when parameter object is not
144154
* documented.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Hello.
3+
*/
4+
package foo.bar;
5+
6+
public class BinaryContent {
7+
// Binary content: □▢■▣▤▥▦▧▨▩
8+
private static String binaryText = "Binary content: \u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588\u2589";
9+
}

0 commit comments

Comments
 (0)