Ignore charsets when checking for HTML index file
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Sun, 18 Sep 2016 17:49:40 +0000 (19:49 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Sun, 18 Sep 2016 17:49:40 +0000 (19:49 +0200)
src/main/java/de/todesbaum/jsite/application/validation/ProjectValidator.java
src/test/java/de/todesbaum/jsite/application/validation/ProjectValidatorTest.java

index 2e03e6c..a25aa9d 100644 (file)
@@ -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<String> 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<String, FileOption> 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));
+       }
+
 }
index 545ab45..b2c3c9c 100644 (file)
@@ -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);