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

Parser parses empty scalar as '~' #182

Open
xnuk opened this issue Dec 1, 2021 · 1 comment
Open

Parser parses empty scalar as '~' #182

xnuk opened this issue Dec 1, 2021 · 1 comment

Comments

@xnuk
Copy link

xnuk commented Dec 1, 2021

yaml-rust parses empty scalar as ~:

use yaml_rust::parser::{Event, EventReceiver, Parser};

struct Printer;
impl EventReceiver for Printer {
    fn on_event(&mut self, ev: Event) {
        println!("{:?}", ev);
    }
}

let text: &str = r#"
foo:
bar: ~
"#

Parser::new(text.chars()).load(&mut Recv, false)?;

/* output:
StreamStart
DocumentStart
MappingStart(0)
Scalar("foo", Plain, 0, None)
Scalar("~", Plain, 0, None)
Scalar("bar", Plain, 0, None)
Scalar("~", Plain, 0, None)
MappingEnd
DocumentEnd
*/

while libyaml's yaml_parser_parse does not (I did FFI by myself):

StreamStart
DocumentStart
MappingStart { anchor: None }
Scalar { anchor: None, value: "foo" }
Scalar { anchor: None, value: "" }
Scalar { anchor: None, value: "bar" }
Scalar { anchor: None, value: "~" }
MappingEnd
DocumentEnd
StreamEnd

Note: tag:yaml.org,2002:null is not in Failsafe schema1 (and is in JSON schema2).

Footnotes

  1. https://yaml.org/spec/1.2.2/#101-failsafe-schema

  2. https://yaml.org/spec/1.2.2/#102-json-schema

@xnuk
Copy link
Author

xnuk commented Dec 9, 2021

Made test case for this: #183

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

No branches or pull requests

1 participant