From fd3bd2c16b6d9d617bb70478c11ac756a726999f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 18 Sep 2016 19:49:40 +0200 Subject: [PATCH] Ignore charsets when checking for HTML index file --- .../todesbaum/jsite/application/validation/ProjectValidator.java | 9 +++++++-- .../jsite/application/validation/ProjectValidatorTest.java | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/todesbaum/jsite/application/validation/ProjectValidator.java b/src/main/java/de/todesbaum/jsite/application/validation/ProjectValidator.java index 2e03e6c..a25aa9d 100644 --- a/src/main/java/de/todesbaum/jsite/application/validation/ProjectValidator.java +++ b/src/main/java/de/todesbaum/jsite/application/validation/ProjectValidator.java @@ -10,6 +10,7 @@ import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.Stream; import de.todesbaum.jsite.application.FileOption; import de.todesbaum.jsite.application.Project; @@ -44,8 +45,7 @@ public class ProjectValidator { } String indexFile = project.getIndexFile(); boolean hasIndexFile = (indexFile != null) && (indexFile.length() > 0); - List allowedIndexContentTypes = Arrays.asList("text/html", "application/xhtml+xml"); - if (hasIndexFile && !allowedIndexContentTypes.contains(project.getFileOption(indexFile).getMimeType())) { + if (hasIndexFile && indexFileIsNotHtml(project, indexFile)) { checkReport.addIssue("warning.index-not-html", false); } Map fileOptions = project.getFileOptions(); @@ -104,4 +104,9 @@ public class ProjectValidator { return checkReport; } + private static boolean indexFileIsNotHtml(Project project, String indexFile) { + return Stream.of("text/html", "application/xhtml+xml") + .noneMatch(mimeType -> project.getFileOption(indexFile).getMimeType().startsWith(mimeType)); + } + } diff --git a/src/test/java/de/todesbaum/jsite/application/validation/ProjectValidatorTest.java b/src/test/java/de/todesbaum/jsite/application/validation/ProjectValidatorTest.java index 545ab45..b2c3c9c 100644 --- a/src/test/java/de/todesbaum/jsite/application/validation/ProjectValidatorTest.java +++ b/src/test/java/de/todesbaum/jsite/application/validation/ProjectValidatorTest.java @@ -99,6 +99,13 @@ public class ProjectValidatorTest { } @Test + public void usingHtmlMimeTypeWithCharsetForIndexFileDoesNotResultInWarning() { + project.getFileOption("index.html").setMimeType("text/html; charset=UTF-8"); + CheckReport checkReport = validateProject(project); + assertThat(checkReport.getIssues(), not(hasItem(new Issue("warning.index-not-html", false)))); + } + + @Test public void notInsertingTheIndexFileAnyFileResultsInError() { project.getFileOption("index.html").setInsert(false); project.getFileOption("index.html").setInsertRedirect(false); -- 2.7.4