configparser: skip space characters

Summary:
Previously, a line with all space characters is considered "illegal" and I
didn't handle it. It would actually be parsed as part of config name.

Let's skip them. So config files with spaces would behave sanely.

Reviewed By: DurhamG

Differential Revision: D8887370

fbshipit-source-id: e55d221d281fc58b2d2efbcb9196e7f68a78d719
This commit is contained in:
Jun Wu 2018-08-08 17:15:27 -07:00 committed by Facebook Github Bot
parent 4f6c9b1a5e
commit 0ea7f4aa94

View File

@ -265,7 +265,7 @@ impl ConfigSet {
while pos < buf.len() {
match buf[pos] {
b'\n' | b'\r' => pos += 1,
b'\n' | b'\r' | b' ' | b'\t' => pos += 1,
b'[' => {
let section_start = pos + 1;
match memchr(b']', &buf.as_ref()[section_start..]) {
@ -653,6 +653,18 @@ mod tests {
assert_eq!(sources[1].location().unwrap(), (PathBuf::new(), 52..53));
}
#[test]
fn test_parse_spaces() {
let mut cfg = ConfigSet::new();
cfg.parse(
"[a]\n\
\t#\n\
x=1",
&"".into(),
);
assert_eq!(cfg.get("a", "x"), Some("1".into()));
}
#[test]
fn test_parse_errors() {
let mut cfg = ConfigSet::new();