From 8d5c1b3886746b9001f162c6759f50f2251ba6a0 Mon Sep 17 00:00:00 2001 From: Alexis Date: Thu, 29 Aug 2024 20:45:06 +0200 Subject: [PATCH] Fix the UTF-8 with BOM encoding compatibility for ignore files --- .../filter/artifact/parser/ArtifactFilterParser.java | 4 ++++ .../filter/artifact/parser/ArtifactFilterParserTest.java | 3 +++ src/test/resources/.mvnchk-ignore_bom | 1 + 3 files changed, 8 insertions(+) create mode 100644 src/test/resources/.mvnchk-ignore_bom diff --git a/src/main/java/com/github/alexisjehan/mvncheck/core/component/filter/artifact/parser/ArtifactFilterParser.java b/src/main/java/com/github/alexisjehan/mvncheck/core/component/filter/artifact/parser/ArtifactFilterParser.java index 7f79796..a96e0b6 100644 --- a/src/main/java/com/github/alexisjehan/mvncheck/core/component/filter/artifact/parser/ArtifactFilterParser.java +++ b/src/main/java/com/github/alexisjehan/mvncheck/core/component/filter/artifact/parser/ArtifactFilterParser.java @@ -98,6 +98,10 @@ public static ArtifactFilter parse(final Path ignoreFile) throws IOException { Ensure.notNullAndFile("ignoreFile", ignoreFile); logger.info("Parsing the {} ignore file", () -> ToString.toString(ignoreFile)); try (var reader = Readers.of(ignoreFile)) { + reader.mark(1); + if ('\ufeff' != reader.read()) { // UTF-8 BOM character + reader.reset(); + } return parse(reader); } catch (final ArtifactFilterParseException e) { throw e.with(ignoreFile); diff --git a/src/test/java/com/github/alexisjehan/mvncheck/core/component/filter/artifact/parser/ArtifactFilterParserTest.java b/src/test/java/com/github/alexisjehan/mvncheck/core/component/filter/artifact/parser/ArtifactFilterParserTest.java index becb217..b01a556 100644 --- a/src/test/java/com/github/alexisjehan/mvncheck/core/component/filter/artifact/parser/ArtifactFilterParserTest.java +++ b/src/test/java/com/github/alexisjehan/mvncheck/core/component/filter/artifact/parser/ArtifactFilterParserTest.java @@ -54,6 +54,9 @@ void testParsePath() { assertThatNoException().isThrownBy( () -> ArtifactFilterParser.parse(Path.of("src", "test", "resources", ".mvnchk-ignore_foo")) ); + assertThatNoException().isThrownBy( + () -> ArtifactFilterParser.parse(Path.of("src", "test", "resources", ".mvnchk-ignore_bom")) + ); } @Test diff --git a/src/test/resources/.mvnchk-ignore_bom b/src/test/resources/.mvnchk-ignore_bom new file mode 100644 index 0000000..5740ff6 --- /dev/null +++ b/src/test/resources/.mvnchk-ignore_bom @@ -0,0 +1 @@ +# comment \ No newline at end of file