From: David ‘Bombe’ Roden Date: Sun, 18 Sep 2016 17:49:40 +0000 (+0200) Subject: Ignore charsets when checking for HTML index file X-Git-Tag: 0.14^2~10 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=fd3bd2c16b6d9d617bb70478c11ac756a726999f;p=jSite.git Ignore charsets when checking for HTML index file --- 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);