diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2015-02-11 17:04:23 -0800 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2015-02-11 17:08:13 -0800 |
commit | debe7aedda3665702d1f99a3ffb4a123a6c44e9c (patch) | |
tree | 8c03529f1eec95632f9f5f030032b1f177532686 /actionpack/lib/action_dispatch.rb | |
parent | 933decceaf6092020ba7ba768b51b2db9d5b882f (diff) | |
download | rails-debe7aedda3665702d1f99a3ffb4a123a6c44e9c.tar.gz rails-debe7aedda3665702d1f99a3ffb4a123a6c44e9c.tar.bz2 rails-debe7aedda3665702d1f99a3ffb4a123a6c44e9c.zip |
Properly dump primitive-like AS::SafeBuffer strings as YAML
`coder.represent_scalar` means something along the lines of "Here is a quoted
string, you can just add it to the output", which is not the case here. It only
works for simple strings that can appear unquoted in YAML, but causes problems
for e.g. primitive-like strings ("1", "true").
`coder.represent_object` on the other hand, means that "This is the Ruby-object
representation for this thing suitable for use in YAML dumping", which is what
we want here.
Before:
YAML.load ActiveSupport::SafeBuffer.new("Hello").to_yaml # => "Hello"
YAML.load ActiveSupport::SafeBuffer.new("true").to_yaml # => true
YAML.load ActiveSupport::SafeBuffer.new("false").to_yaml # => false
YAML.load ActiveSupport::SafeBuffer.new("1").to_yaml # => 1
YAML.load ActiveSupport::SafeBuffer.new("1.1").to_yaml # => 1.1
After:
YAML.load ActiveSupport::SafeBuffer.new("Hello").to_yaml # => "Hello"
YAML.load ActiveSupport::SafeBuffer.new("true").to_yaml # => "true"
YAML.load ActiveSupport::SafeBuffer.new("false").to_yaml # => "false"
YAML.load ActiveSupport::SafeBuffer.new("1").to_yaml # => "1"
YAML.load ActiveSupport::SafeBuffer.new("1.1").to_yaml # => "1.1"
If we ever want Ruby to behave more like PHP or JavaScript though, this is an
excellent trick to use ;)
Diffstat (limited to 'actionpack/lib/action_dispatch.rb')
0 files changed, 0 insertions, 0 deletions