diff --git a/saphyr/src/parser.rs b/saphyr/src/parser.rs index 78408e4..678f841 100644 --- a/saphyr/src/parser.rs +++ b/saphyr/src/parser.rs @@ -58,8 +58,8 @@ impl Event { Event::Scalar("~".to_owned(), TScalarStyle::Plain, 0, None) } - fn empty_scalar_with_anchor(anchor: usize, tag: TokenType) -> Event { - Event::Scalar("".to_owned(), TScalarStyle::Plain, anchor, Some(tag)) + fn empty_scalar_with_anchor(anchor: usize, tag: Option) -> Event { + Event::Scalar("".to_owned(), TScalarStyle::Plain, anchor, tag) } } @@ -453,7 +453,7 @@ impl> Parser { // ex 7.2, an empty scalar can follow a secondary tag _ if tag.is_some() || anchor_id > 0 => { self.pop_state(); - Ok(Event::empty_scalar_with_anchor(anchor_id, tag.unwrap())) + Ok(Event::empty_scalar_with_anchor(anchor_id, tag)) }, _ => { Err(ScanError::new(tok.0, "while parsing a node, did not find expected node content")) } } diff --git a/saphyr/src/yaml.rs b/saphyr/src/yaml.rs index f843491..04a2fca 100644 --- a/saphyr/src/yaml.rs +++ b/saphyr/src/yaml.rs @@ -404,6 +404,14 @@ a1: &DEFAULT } + #[test] + fn test_github_27() { + // https://github.com/chyh1990/yaml-rust/issues/27 + let s = "&a"; + let out = YamlLoader::load_from_str(&s).unwrap(); + let doc = &out[0]; + assert_eq!(doc.as_str().unwrap(), ""); + } #[test] fn test_plain_datatype() {