Merge pull request #96 from chyh1990/fix_boolean_quotes
fix boolean escape and quotes
This commit is contained in:
commit
e7637188a8
1 changed files with 11 additions and 7 deletions
|
@ -307,7 +307,10 @@ fn need_quotes(string: &str) -> bool {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|| [// http://yaml.org/type/bool.html
|
|| [// http://yaml.org/type/bool.html
|
||||||
"y","Y","yes","Yes","YES","n","N","no","No","NO",
|
// Note: 'y', 'Y', 'n', 'N', is not quoted deliberately, as in libyaml. PyYAML also parse
|
||||||
|
// them as string, not booleans, although it is volating the YAML 1.1 specification.
|
||||||
|
// See https://github.com/dtolnay/serde-yaml/pull/83#discussion_r152628088.
|
||||||
|
"yes","Yes","YES","no","No","NO",
|
||||||
"True", "TRUE", "true", "False", "FALSE", "false",
|
"True", "TRUE", "true", "False", "FALSE", "false",
|
||||||
"on","On","ON","off","Off","OFF",
|
"on","On","ON","off","Off","OFF",
|
||||||
// http://yaml.org/type/null.html
|
// http://yaml.org/type/null.html
|
||||||
|
@ -409,6 +412,7 @@ field: ":"
|
||||||
field2: "{"
|
field2: "{"
|
||||||
field3: "\\"
|
field3: "\\"
|
||||||
field4: "\n"
|
field4: "\n"
|
||||||
|
field5: "can't avoid quote"
|
||||||
float: "2.6"
|
float: "2.6"
|
||||||
int: "4"
|
int: "4"
|
||||||
nullable: "null"
|
nullable: "null"
|
||||||
|
@ -425,7 +429,7 @@ products:
|
||||||
"true": bool key
|
"true": bool key
|
||||||
"{}": empty hash key
|
"{}": empty hash key
|
||||||
x: test
|
x: test
|
||||||
"y": "can't avoid quoting here"
|
y: avoid quoting here
|
||||||
z: string with spaces"#;
|
z: string with spaces"#;
|
||||||
|
|
||||||
let docs = YamlLoader::load_from_str(&s).unwrap();
|
let docs = YamlLoader::load_from_str(&s).unwrap();
|
||||||
|
@ -466,13 +470,13 @@ null0: ~
|
||||||
- "TRUE"
|
- "TRUE"
|
||||||
- "False"
|
- "False"
|
||||||
- "FALSE"
|
- "FALSE"
|
||||||
- "y"
|
- y
|
||||||
- "Y"
|
- Y
|
||||||
- "yes"
|
- "yes"
|
||||||
- "Yes"
|
- "Yes"
|
||||||
- "YES"
|
- "YES"
|
||||||
- "n"
|
- n
|
||||||
- "N"
|
- N
|
||||||
- "no"
|
- "no"
|
||||||
- "No"
|
- "No"
|
||||||
- "NO"
|
- "NO"
|
||||||
|
@ -494,7 +498,7 @@ bool1: false"#;
|
||||||
emitter.dump(doc).unwrap();
|
emitter.dump(doc).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(expected, writer, "actual:\n\n{}\n", writer);
|
assert_eq!(expected, writer, "expected:\n{}\nactual:\n{}\n", expected, writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue