diff --git a/src/main/java/org/jbake/app/Parser.java b/src/main/java/org/jbake/app/Parser.java index 3840c82fc..e3f413915 100644 --- a/src/main/java/org/jbake/app/Parser.java +++ b/src/main/java/org/jbake/app/Parser.java @@ -151,10 +151,10 @@ private boolean hasHeader(List contents) { } header.add(line); if (line.contains("=")) { - if (line.startsWith("type=")) { + if (line.matches("^type\\s*=.*")) { typeFound = true; } - if (line.startsWith("status=")) { + if (line.matches("^status\\s*=.*")) { statusFound = true; } } @@ -175,13 +175,9 @@ private boolean hasHeader(List contents) { } } -// if (!headerValid || !statusFound || !typeFound) { -// return false; -// } -// return true; return headerValid && statusFound && typeFound; } - + /** * Process the header of the file. * @@ -193,7 +189,7 @@ private void processHeader(List contents, final Map cont if (line.equals(END_OF_HEADER)) { break; } else { - String[] parts = line.split("=",2); + String[] parts = line.split("\\s*=\\s*",2); if (parts.length == 2) { if (parts[0].equalsIgnoreCase("date")) { DateFormat df = new SimpleDateFormat(config.getString(Keys.DATE_FORMAT)); diff --git a/src/test/java/org/jbake/app/ParserTest.java b/src/test/java/org/jbake/app/ParserTest.java index a40d1f80f..0db13c74a 100644 --- a/src/test/java/org/jbake/app/ParserTest.java +++ b/src/test/java/org/jbake/app/ParserTest.java @@ -37,6 +37,7 @@ public class ParserTest { private File validAsciiDocFileWithBlankFirstLineInHeader; private File validAsciiDocFileWithEmptyRandomLineInHeader; private File validAsciiDocFileWithBlankRandomLineInHeader; + private File validAsciiDocFileWithSpacesAroundEqualInHeader; private String validHeader = "title=This is a Title = This is a valid Title" + EOL + "status=draft" + EOL @@ -54,6 +55,13 @@ public class ParserTest { private String validHeaderWithBlankRandomLine = validHeader.substring(0, pos) + " " + EOL + validHeader.substring(pos + 1); + private String validHeaderWithSpacesAroundEqual = "title = This is a Title = This is a valid Title" + EOL + + "status =draft" + EOL + + "type= post"+ EOL + + "date = 2013-09-02"+ EOL + + END_OF_HEADER; + + @Before public void createSampleFile() throws Exception { rootPath = new File(this.getClass().getResource(".").getFile()); @@ -148,11 +156,18 @@ public void createSampleFile() throws Exception { out.println("

This is a test with empty random line in header.

"); out.close(); - validAsciiDocFileWithBlankRandomLineInHeader = folder.newFile("validwithblankrandomlineinheader.ad");System.out.println("---#b> "+validHeaderWithBlankRandomLine.replaceAll(EOL, "EOL")); + validAsciiDocFileWithBlankRandomLineInHeader = folder.newFile("validwithblankrandomlineinheader.ad"); out = new PrintWriter(validAsciiDocFileWithBlankRandomLineInHeader); out.println(validHeaderWithBlankRandomLine); out.println("

This is a test with blank random line in header.

"); out.close(); + + validAsciiDocFileWithSpacesAroundEqualInHeader = folder.newFile("validwithspacesaroundequalinheader.ad"); + out = new PrintWriter(validAsciiDocFileWithSpacesAroundEqualInHeader); + out.println(validHeaderWithSpacesAroundEqual); + out.println("

This is a test with spaces around equals in header.

"); + out.close(); + } @Test @@ -258,4 +273,10 @@ public void parseValidAsciiDocFileWithBlankRandomLineInHeader() { Assert.assertNotNull(map); } + @Test + public void parseValidAsciiDocFileWithSpacesAroundEqualInHeader() { + Map map = parser.processFile(validAsciiDocFileWithSpacesAroundEqualInHeader); + Assert.assertNotNull(map); + } + }