Skip to content
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

Several blank lines in multi-line scalar values collapsed to one #10

Closed
Witiko opened this issue Sep 7, 2021 · 5 comments · Fixed by #11
Closed

Several blank lines in multi-line scalar values collapsed to one #10

Witiko opened this issue Sep 7, 2021 · 5 comments · Fixed by #11

Comments

@Witiko
Copy link

Witiko commented Sep 7, 2021

See peposso#13:

The following two YAML documents will produce the same output when passed to tinyyaml.parse().

first_input = [[
abstract: |
  This is *the abstract*.
  It consists of two paragraphs.
]]

second_input = [[
abstract: |
  This is *the abstract*.

  It consists of two paragraphs.
]]

tinyyaml = require("tinyyaml")
for k, v in pairs(tinyyaml.parse(first_input)) do
  print(k, v)
end
for k, v in pairs(tinyyaml.parse(second_input)) do
  print(k, v)
end

Executing the above code in Lua 5.2.4 and in Lua 5.3 gives me the following results:

abstract        This is *the abstract*.
It consists of two paragraphs.

abstract        This is *the abstract*.
It consists of two paragraphs.

Here is the expected output:

abstract        This is *the abstract*.
It consists of two paragraphs.

abstract        This is *the abstract*.

It consists of two paragraphs.

The following seems to be the cause:

if s[i] == '' then

This behavior is contrary to the YAML spec (emphasis mine):

The literal style is denoted by the “|” indicator. It is the simplest, most restricted, and most readable scalar style. [...] Inside literal scalars, all (indented) characters are considered to be content, including white space characters. Note that all line break characters are normalized. In addition, empty lines are not folded, though final line breaks and trailing empty lines are chomped.

YAML Ain’t Markup Language (YAML™) Version 1.2, 3rd Edition, Patched at 2009-10-01, Section 8.1.2. Literal Style

@spacewander
Copy link

The empty lines are removed from the beginning...

lines = select(lines, function(s) return not isemptyline(s) end)

@Witiko
Copy link
Author

Witiko commented Sep 8, 2021

@spacewander You are right. Is this intentional, or should I take a stab at fixing it? In my application, blank lines are meaningful.

@spacewander
Copy link

I think the author missed this corner case.

@kalekje
Copy link

kalekje commented Sep 11, 2021

Upvoting this! Noticed the same issue.

Witiko added a commit to Witiko/lua-tinyyaml that referenced this issue Sep 11, 2021
Witiko added a commit to Witiko/lua-tinyyaml that referenced this issue Sep 11, 2021
Witiko added a commit to Witiko/lua-tinyyaml that referenced this issue Sep 11, 2021
Witiko added a commit to Witiko/lua-tinyyaml that referenced this issue Sep 12, 2021
@Witiko
Copy link
Author

Witiko commented Sep 12, 2021

@spacewander @kalekje I propose a fix in #11.

Witiko added a commit to TeXhackse/markdown that referenced this issue Sep 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants