configparser: fix windows EOL handling

Summary:
Without this patch, all hg commands will fail with our current config:

  hg: parse error: <filename>
   --> 6:5
    |
  6 |     commandexception
    |     ^---
    |
    = expected new_line

The config is:

  [blackbox]
  track = command
      commandexception
      ...

Because "\r\n" was treated as the same as double "\n"s.

Reviewed By: ryanmce

Differential Revision: D9494909

fbshipit-source-id: 64ef173c69f3cf61d4e71116c581dbca72fb2c4b
This commit is contained in:
Jun Wu 2018-08-23 23:54:11 -07:00 committed by Facebook Github Bot
parent f32aa15ebd
commit 8356dbd506
3 changed files with 9 additions and 9 deletions

View File

@ -610,7 +610,7 @@ mod tests {
\n\
[x]\n\
m = this\n \
value has\n \
value has\r\n \
multi lines\n\
; comment again\n\
n =\n",
@ -637,7 +637,7 @@ mod tests {
assert_eq!(sources[1].source(), "test_parse_basic");
assert_eq!(sources[0].location().unwrap(), (PathBuf::new(), 8..9));
assert_eq!(sources[1].location().unwrap(), (PathBuf::new(), 38..40));
assert_eq!(sources[1].file_content().unwrap().len(), 99);
assert_eq!(sources[1].file_content().unwrap().len(), 100);
}
#[test]

View File

@ -11,7 +11,7 @@
// However, `#[grammar = "spec.pest"]` does not play well with Buck build,
// because pest_derive cannot find "spec.pest" in buck build environment.
// Therefore this file is @generated. @no-lint.
// pest-checksum: 1fa4fbe929a8b3e6c073fcd1e46cae2bc30d23f7.
// pest-checksum: d00ac1967ce2bd9ff78af9d3e1345058a648964c.
#[allow(dead_code, non_camel_case_types)]
@ -58,7 +58,7 @@ impl ::pest::Parser<Rule> for ConfigParser {
{
pos.match_string("\n").or_else(|pos|
{
pos.match_string("\r")
pos.match_string("\r\n")
})
})
}
@ -764,12 +764,12 @@ impl ::pest::Parser<Rule> for ConfigParser {
})
}
#[inline]
fn soi<'i>(pos: ::pest::Position<'i>,
fn any<'i>(pos: ::pest::Position<'i>,
_: &mut ::pest::ParserState<'i, Rule>)
->
::std::result::Result<::pest::Position<'i>,
::pest::Position<'i>> {
pos.at_start()
pos.skip(1)
}
#[inline]
fn eoi<'i>(pos: ::pest::Position<'i>,
@ -780,12 +780,12 @@ impl ::pest::Parser<Rule> for ConfigParser {
pos.at_end()
}
#[inline]
fn any<'i>(pos: ::pest::Position<'i>,
fn soi<'i>(pos: ::pest::Position<'i>,
_: &mut ::pest::ParserState<'i, Rule>)
->
::std::result::Result<::pest::Position<'i>,
::pest::Position<'i>> {
pos.skip(1)
pos.at_start()
}
#[inline]
#[allow(dead_code)]

View File

@ -22,7 +22,7 @@
// Same applies to "directive" and "bracket"s.
new_line = { "\n" | "\r" }
new_line = { "\n" | "\r\n" }
space = { " " | "\t" }
comment_start = { ("#" | ";") }