Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Strings that start with non-word characters should double quote without exclamation mark #106

Merged
merged 1 commit into from

2 participants

@atambo
Psych.dump("@123'abc")

Before this commit:

--- ! '@123''abc'

After this commit:

--- "@123'abc"

This makes yaml output look much cleaner.

@tenderlove
Owner

I'm not sure. I buy the argument for using literal style for multiline strings, but why for strings like this? I think it would be better if we just got rid of the ! and made it:

--- '!123abc'

WDYT?

@atambo

I'd be happy with with removing the ! as that is the confusing part.

@atambo

@tenderlove, I've updated the commit. Looks even cleaner, thanks!

@atambo atambo Strings that start with non-word characters should double quote witho…
…ut exclamation mark

Before this commit:

--- ! '@123''abc'

After this commit:

--- "@123'abc"
086fe08
@atambo

I've also changed it to use double quotes instead of single quotes because when a string contains single quotes it just adds another single quote which splits the string in half instead of escaping it.

@tenderlove
Owner

Great, thanks! :heart:

@tenderlove tenderlove merged commit d5757ea into tenderlove:master
@Exoth Exoth referenced this pull request
Closed

Double quotes #157

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 9, 2012
  1. @atambo

    Strings that start with non-word characters should double quote witho…

    atambo authored
    …ut exclamation mark
    
    Before this commit:
    
    --- ! '@123''abc'
    
    After this commit:
    
    --- "@123'abc"
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 0 deletions.
  1. +3 −0  lib/psych/visitors/yaml_tree.rb
  2. +6 −0 test/psych/test_yaml.rb
View
3  lib/psych/visitors/yaml_tree.rb
@@ -242,6 +242,9 @@ def visit_String o
elsif o =~ /\n/
quote = true
style = Nodes::Scalar::LITERAL
+ elsif o =~ /^\W/
+ quote = true
+ style = Nodes::Scalar::DOUBLE_QUOTED
else
quote = !(String === @ss.tokenize(o))
plain = !quote
View
6 test/psych/test_yaml.rb
@@ -1271,4 +1271,10 @@ def test_multiline_string_uses_literal_style
yaml = Psych.dump("multi\nline\nstring")
assert_match("|", yaml)
end
+
+ def test_string_starting_with_non_word_character_uses_double_quotes_without_exclamation_mark
+ yaml = Psych.dump("@123'abc")
+ assert_match("\"", yaml)
+ refute_match("!", yaml)
+ end
end
Something went wrong with that request. Please try again.