-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
YAML front matter parser does not strip single or double quotes on scalars #260
Comments
Yeah you're right, that's broken. The reason for that is that it currently does some manual (and very limited) YAML parsing, see So two ways to fix this:
Do you have any opinions on those @JakeWharton? If we do 1, we can also consider adding support for retrieving the raw YAML source (as a single |
Extend our manual parser to handle string values that use single or double quotes. The support is limited and doesn't implement the full YAML spec (e.g. no support for escapes like `\n`). At some point we should either depend on a real YAML parser or expose the raw YAML source so that users can parse it themselves. Fixes #260.
Created a PR for 1., see test cases here: https://github.com/commonmark/commonmark-java/pull/261/files#diff-3bf17f3edca5ff1728b4e1918880038dcbe66f231114c2a1e40729793d07bb96R286 |
Yeah I ended up doing a form of the String-extraction where I simply pre-processed the input data to conditionally extract the front matter per its "specification". The upside is I can parse front matter on all files not just markdown (not sure I specifically need this). The downside is lost using this library's types as a unified model and instead have my own composite type of front matter + markdown. I don't recall whether I'm using the 1.1 or 1.2 version of SnakeYAML. I'm under-educated on the difference. For this specific quoting issue, you must quote values if they contain a colon in order for Jekyll's parser to correctly parse the value. Since I'm sharing front matter-containing markdown files with Jekyll as well as my tool I need to honor that. My example above doesn't have a colon, but I tend to copy/paste the last blog post when I create a new one and so the quoting has now persisted to about half my files. |
Ok, so sounds like my PR will be enough to solve the issue for you?: https://github.com/commonmark/commonmark-java/pull/261/files#diff-3bf17f3edca5ff1728b4e1918880038dcbe66f231114c2a1e40729793d07bb96R286 |
Yep! Looks good. |
Alright, released this fix as 0.19.0 🎉: https://github.com/commonmark/commonmark-java/blob/main/CHANGELOG.md#0190---2022-06-02 |
Steps to reproduce the problem (provide example Markdown if applicable):
Expected behavior:
Actual behavior:
Note the retained single quotes (
'
) surrounding the value. This is also a problem with double quotes ("
).YAML spec dictates behavior on unquoted, single-quoted, and double-quoted scalars: https://yaml.org/spec/1.2.2/#73-flow-scalar-styles
The text was updated successfully, but these errors were encountered: