Skip to content

Commit

Permalink
Merge branch 'master' into prevent-too-deep-recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay authored Sep 15, 2018
2 parents d61b49c + 2c2d40f commit 644ee83
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ repository = "https://github.com/chyh1990/yaml-rust"
linked-hash-map = ">=0.0.9, <0.6"

[dev-dependencies]
quickcheck = "0.6"
quickcheck = "0.7"
56 changes: 56 additions & 0 deletions src/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,62 @@ c: ~
assert_eq!(first[0]["important"].as_bool().unwrap(), true);
}

fn test_indentation_equality() {

let four_spaces = YamlLoader::load_from_str(r#"
hash:
with:
indentations
"#).unwrap().into_iter().next().unwrap();

let two_spaces = YamlLoader::load_from_str(r#"
hash:
with:
indentations
"#).unwrap().into_iter().next().unwrap();

let one_space = YamlLoader::load_from_str(r#"
hash:
with:
indentations
"#).unwrap().into_iter().next().unwrap();

let mixed_spaces = YamlLoader::load_from_str(r#"
hash:
with:
indentations
"#).unwrap().into_iter().next().unwrap();

assert_eq!(four_spaces, two_spaces);
assert_eq!(two_spaces, one_space);
assert_eq!(four_spaces, mixed_spaces);
}

#[test]
fn test_two_space_indentations() {
// https://github.com/kbknapp/clap-rs/issues/965

let s = r#"
subcommands:
- server:
about: server related commands
subcommands2:
- server:
about: server related commands
subcommands3:
- server:
about: server related commands
"#;

let out = YamlLoader::load_from_str(&s).unwrap();
let doc = &out.into_iter().next().unwrap();

println!("{:#?}", doc);
assert_eq!(doc["subcommands"][0]["server"], Yaml::Null);
assert!(doc["subcommands2"][0]["server"].as_hash().is_some());
assert!(doc["subcommands3"][0]["server"].as_hash().is_some());
}

#[test]
fn test_recursion_depth_check_objects() {
let s = "{a:".repeat(10_000) + &"}".repeat(10_000);
Expand Down

0 comments on commit 644ee83

Please sign in to comment.