Author: stephenc Date: Thu Nov 21 09:03:24 2013 New Revision: 1544070 URL: http://svn.apache.org/r1544070 Log: [FIXED DOXIA-509] Multi-markdown metadata is too greedy.
- The regex is in multi-line mode so \s will match newlines thus allowing a single empty line to be considered as a valid continuation line. Changing to \p{Blank} fixes the issue. - The original test case did not validate the expected output correctly, so updated the test case to have more than one section (one symptom of the bug was that only the last section header and paragraph would avoid being mistaken for metadata continuation) and the expected output to match the new input correctly Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/main/java/org/apache/maven/doxia/module/markdown/MarkdownParser.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownParserTest.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/resources/metadata.md Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/main/java/org/apache/maven/doxia/module/markdown/MarkdownParser.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/main/java/org/apache/maven/doxia/module/markdown/MarkdownParser.java?rev=1544070&r1=1544069&r2=1544070&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/main/java/org/apache/maven/doxia/module/markdown/MarkdownParser.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/main/java/org/apache/maven/doxia/module/markdown/MarkdownParser.java Thu Nov 21 09:03:24 2013 @@ -70,12 +70,13 @@ public class MarkdownParser * Regex that identifies a multimarkdown-style metadata section at the start of the document */ private static final String MULTI_MARKDOWN_METADATA_SECTION = - "^(((?:[^\\s:][^:]*):(?:.*(?:\r?\n\\s[^\\s].*)*\r?\n))+)(?:\\s*\r?\n)"; + "^(((?:[^\\s:][^:]*):(?:.*(?:\r?\n\\p{Blank}+[^\\s].*)*\r?\n))+)(?:\\s*\r?\n)"; /** * Regex that captures the key and value of a multimarkdown-style metadata entry. */ - private static final String MULTI_MARKDOWN_METADATA_ENTRY = "([^\\s:][^:]*):(.*(?:\r?\n\\s[^\\s].*)*)\r?\n"; + private static final String MULTI_MARKDOWN_METADATA_ENTRY = + "([^\\s:][^:]*):(.*(?:\r?\n\\p{Blank}+[^\\s].*)*)\r?\n"; /** * In order to ensure that we have minimal risk of false positives when slurping metadata sections, the Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownParserTest.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownParserTest.java?rev=1544070&r1=1544069&r2=1544070&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownParserTest.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/java/org/apache/maven/doxia/module/markdown/MarkdownParserTest.java Thu Nov 21 09:03:24 2013 @@ -206,7 +206,9 @@ public class MarkdownParserTest Iterator<SinkEventElement> it = parseFileToEventTestingSink( "metadata" ).getEventList().iterator(); assertEquals( it, "head", "title", "text", "title_", "author", "text", "author_", "date", "text", "date_", - "head_", "body", "paragraph", "text", "paragraph_", "body_" ); + "head_", "body", "unknown", "text", "unknown", "paragraph", "text", "paragraph_", "section1", + "sectionTitle1", "text", "sectionTitle1_", "paragraph", "text", "paragraph_", "section1_", + "body_" ); assertFalse( it.hasNext() ); } Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/resources/metadata.md URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/resources/metadata.md?rev=1544070&r1=1544069&r2=1544070&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/resources/metadata.md (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-markdown/src/test/resources/metadata.md Thu Nov 21 09:03:24 2013 @@ -4,4 +4,8 @@ date: 2013 # The document -Some text \ No newline at end of file +Some text + +## A subheading + +Some more text \ No newline at end of file