Modify

Ticket #69 (closed defect: invalid)

Opened 6 years ago

Last modified 6 years ago

scalar value of escaped double-newline parsed as a single newline

Reported by: anonymous Owned by: xi
Priority: normal Component: libyaml
Severity: normal Keywords:
Cc:

Description

When parsing the following: terminator : "\n\n"

The value of the right side scalar is returned as \n, rather than \n\n. Likewise, four newlines ("\n\n\n\n") is parsed as three ("\n\n\n").

Attachments

yaml_test.tar.gz Download (75.0 KB) - added by anonymous 6 years ago.
Here is a code example that illustrates the problem. Look at the 3 newlines following the 'terminator' scalar. They end up being returned as 2 newlines.

Change History

comment:1 Changed 6 years ago by xi

It works fine for me both with pure Python PyYAML and LibYAML bindings:

>>> import yaml
>>> yaml.load(r'terminator : "\n\n"')
{'terminator': '\n\n'}
>>> yaml.load(r'terminator : "\n\n"', Loader=yaml.CLoader)
{'terminator': '\n\n'}

Could you post a code snippet and a YAML file that produce the problem?

Changed 6 years ago by anonymous

Here is a code example that illustrates the problem. Look at the 3 newlines following the 'terminator' scalar. They end up being returned as 2 newlines.

comment:2 Changed 6 years ago by xi

  • Status changed from new to closed
  • Resolution set to invalid

Is \n in your examples a new line character or just two symbols: \ and n? PyYAML and LibYAML handle these cases differently:

>>> import yaml
>>> yaml.load('"\n\n"') # two new line characters
'\n'
>>> yaml.load(r'"\n\n"') # four characters: \ n \ n
'\n\n'

In the both cases, PyYAML output is correct, see  http://yaml.org/spec/cvs/current.html#line%20folding/ and  http://yaml.org/spec/cvs/current.html#ns-esc-char.

When N(>1) subsequent new line characters occur in a flow scalar, they are "folded" into N-1 new line characters. A single new line character is replaced with space.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.