Modify

Ticket #240 (new defect)

Opened 2 years ago

Last modified 18 months ago

Block and / or folded literal dumps fail on trailing space

Reported by: yarkot1@… Owned by: xi
Priority: normal Component: pyyaml
Severity: normal Keywords:
Cc:

Description

Goal: Yaml output of both block and folded styles, such as: folded_example: >

I have some text here and then some more here.

literal_style: |

I have some text here and some more here.

Approach: Searching, I found this  http://stackoverflow.com/questions/6432605 approach, which seems to work reasonably well _except_ for a peculiar data situation ("the BUG").

PROBLEM: If the source python dict looks like this:

d = { 'x': literal_unicode('I have some text here\n and some more here.\n') } print(yaml.dump(d))

x: |

I have some text here

and some more here.

If the source has any trailing whitespace before the newlines (tab or spaces tested), then the output changes to this:

d = { 'x': literal_unicode('I have some text here\n and some more here.\t\n') } print(yaml.dump(d))

x: "I have some text here\n and some more here.\t\n"

Likewise for folded representation:

d = { 'x': folded_unicode('I have some text here\n and some more here.\t\n') } print(yaml.dump(d))

x: "I have some text here\n and some more here.\t\n"

d = { 'x': folded_unicode('I have some text here\n and some more here.\n') } print(yaml.dump(d))

x: >

I have some text here

and some more here.


OS/X Snow Leopard; Python Version 2.7.3 pyYaml '3.10'

Attachments

Change History

comment:1 Changed 23 months ago by anonymous

Also, if the block has a '\t', the same thing happens.

Yarko

comment:2 Changed 23 months ago by anonymous

That is: if there is a '\t' character anywhere in the value (regardless of position) the same thing happens.

comment:3 Changed 18 months ago by jcollado

In addition to what has been already said, I've seen that it's possible to load a yaml stream that contains that kind of whitespace successfully:

yaml.load('- string\n- |\n literal string \n- other string')

['string', 'literal string \n', 'other string']

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will be changed from xi. Next status will be 'new'
The owner will be changed from xi to anonymous. Next status will be 'assigned'
Author


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

 
Note: See TracTickets for help on using tickets.