Conversation
…newline The YAML_RE regex required a literal newline character after the closing delimiter (--- or ...). When a Markdown file has a YAML front matter block but ends at the closing delimiter with no trailing newline, the regex failed to match. As a result, get_data() returned an empty metadata dict and the entire front matter block (including the --- markers) as document body. Replace the mandatory trailing \n with (?:\n|$) so the pattern also matches at end-of-string. This is a strict superset: files with a trailing newline continue to match as before. Fixes: YAML_RE in mkdocs/utils/meta.py
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
get_data()inmkdocs/utils/meta.pysilently drops YAML front matter when the file ends without a trailing newline after the closing delimiter (---or...).Reproducer
Root Cause
YAML_REends with a literal\n:This requires a newline character after the closing
---/.... When the closing delimiter is the last byte in the file, there is no such newline and the regex does not match. The parser then falls through to the MultiMarkdown path, which also does not recognise---and returns the entire front-matter block as document content with an empty metadata dict.Fix
Replace the trailing
\nwith(?:\n|$)so the pattern matches both a newline and end-of-string. This is backward-compatible: existing files with trailing newlines continue to match as before.Verification