Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix YAML::PullParser#read_raw #4929

Closed
wants to merge 3 commits into from
Closed

Conversation

ezrast
Copy link

@ezrast ezrast commented Sep 6, 2017

Currently, there are a number of cases where read_raw returns a string that doesn't actually represent the content fed into the parser. This uses Builder to make sure that what comes out represents the same as what went in.

Example of bad behavior:
https://carc.in/#/r/2o8f

require "yaml"

struct Good
  YAML.mapping(
    foo: { type: String, nilable: true }
  )
end

struct Bad1
  YAML.mapping(
    foo: String?
  )
end

alias Bad2 = Hash(String, String | Int32)?

yamls = [
  %q(foo: " x "),
  %q(foo: "x #{y} z"),
  %q(foo: "- oops")
]

yamls.each do |yaml|
  pp Good.from_yaml yaml
  begin
    pp Bad1.from_yaml yaml
  rescue ex
    pp ex.message
  end
  begin
    pp Bad2.from_yaml yaml
  rescue ex
    pp ex.message
  end
  puts "-----"
end

@RX14
Copy link
Contributor

RX14 commented Sep 6, 2017

@jwaldrip how does this PR interact with yours?

@Sija Sija mentioned this pull request Sep 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants