YAML treatment of '#' character in middle of a string

D

David A. Black

Hi --

I'm wondering whether the "#" and everything after it are
really supposed to be taken out of the string in this
example:

irb(main):015:0> YAML.load("---\nstring: one # two")
=> {"string"=>"one"}

I guess I can wrap it all in quotation marks, but I didn't
think I had to.


david
 
W

why the lucky stiff

Treatment of the comment character has long been discussed on the yaml-core
list and has changed a bit in the spec over this year. Currently, any pound
character which is preceded by space trims to the next newline as a comment.
Yes, quotes can overcome this weakness.

---
plain: one #this is a comment
quoted: 'one # this is not a comment'
also plain: one#this is not a comment
and also: one# this is also not a comment

I do agree with the rule. I can see compelling reasons to follow plain
scalars with descriptive comments. I don't see the compelling reason for the
space-pound in plain scalars. But if you have a good use case, hop on
yaml-core ML and lay it out for us, Brother Black.

_why
 
D

Dave Thomas

Treatment of the comment character has long been discussed on the
yaml-core
list and has changed a bit in the spec over this year. Currently, any
pound
character which is preceded by space trims to the next newline as a
comment.
Yes, quotes can overcome this weakness.
I do agree with the rule. I can see compelling reasons to follow plain
scalars with descriptive comments. I don't see the compelling reason
for the
space-pound in plain scalars. But if you have a good use case, hop on
yaml-core ML and lay it out for us, Brother Black.

As it stands right now, though, yaml can't read it's own output, which
strikes me as a fairly major issue;

require 'yaml'
fred = "Call the method #dave"
str = YAML.dump(fred)
fred1 = YAML.load(str)
puts fred1 # => 'Call the method '

For me, this, combined with the stuct bug I mentioned over on -core,
makes YAML unusable for my RI work. At the very least, shouldn't ::dump
escape the output?


Cheers

Dave
 
W

why the lucky stiff

Yeah, that bug was fixed a few hours after you reported it. Checked into Ruby
CVS. I could have sworn I responded, but I must have .. got distracted.

Got a fix for this bug, too. Testing it out just now.

_why
 
D

Dave Thomas

Yeah, that bug was fixed a few hours after you reported it. Checked
into Ruby
CVS. I could have sworn I responded, but I must have .. got
distracted.
I know that feeling :)

Thanks for the fixes: both work great.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,142
Messages
2,570,818
Members
47,362
Latest member
eitamoro

Latest Threads

Top