diff --git a/src/sudoers/ast.rs b/src/sudoers/ast.rs index bc639c772..51518adc8 100644 --- a/src/sudoers/ast.rs +++ b/src/sudoers/ast.rs @@ -512,7 +512,7 @@ impl Parse for Sudo { // the failed "try_nonterminal::" will have consumed the '#' // the most ignominious part of sudoers: having to parse bits of comments parse_include(stream).or_else(|_| { - while stream.eat_not_char('\n') {} + stream.skip_to_newline(); make(Sudo::LineComment) }) }; diff --git a/src/sudoers/basic_parser.rs b/src/sudoers/basic_parser.rs index a26c02b80..00565e44e 100644 --- a/src/sudoers/basic_parser.rs +++ b/src/sudoers/basic_parser.rs @@ -139,7 +139,7 @@ impl Parse for Comment { if !stream.eat_char('#') { return Err(Status::Reject); } - while stream.eat_not_char('\n') {} + stream.skip_to_newline(); make(Comment {}) } } @@ -324,7 +324,7 @@ where let error = |stream: &mut CharStream| unrecoverable!(stream, "{msg}"); result.push(error(stream)); } - while stream.eat_not_char('\n') {} + stream.skip_to_newline(); } } diff --git a/src/sudoers/char_stream.rs b/src/sudoers/char_stream.rs index 59b314aab..53836f9e6 100644 --- a/src/sudoers/char_stream.rs +++ b/src/sudoers/char_stream.rs @@ -32,8 +32,8 @@ impl CharStream<'_> { self.next_if(|c| c == expect_char).is_some() } - pub fn eat_not_char(&mut self, expect_not_char: char) -> bool { - self.next_if(|c| c != expect_not_char).is_some() + pub fn skip_to_newline(&mut self) { + while self.next_if(|c| c != '\n').is_some() {} } pub fn peek(&mut self) -> Option {