Skip to content

Commit

Permalink
Fix grep parse failing cases
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Jan 2, 2022
1 parent a0521e0 commit 2957f6f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/handlers/grep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ fn make_output_config() -> GrepOutputConfig {
enum GrepLineRegex {
WithFileExtensionAndLineNumber,
WithFileExtension,
WithFileExtensionNoSpaces,
WithoutSeparatorCharacters,
}

Expand All @@ -298,6 +299,11 @@ lazy_static! {
make_grep_line_regex(GrepLineRegex::WithFileExtensionAndLineNumber);
}

lazy_static! {
static ref GREP_LINE_REGEX_ASSUMING_FILE_EXTENSION_NO_SPACES: Regex =
make_grep_line_regex(GrepLineRegex::WithFileExtensionNoSpaces);
}

lazy_static! {
static ref GREP_LINE_REGEX_ASSUMING_FILE_EXTENSION: Regex =
make_grep_line_regex(GrepLineRegex::WithFileExtension);
Expand Down Expand Up @@ -343,6 +349,14 @@ fn make_grep_line_regex(regex_variant: GrepLineRegex) -> Regex {
)
"
}
GrepLineRegex::WithFileExtensionNoSpaces => {
r"
( # 1. file name (colons not allowed)
[^:|\ ]+ # try to be strict about what a file path can start with
[^\ ]\.[^.\ :=-]{1,6} # extension
)
"
}
GrepLineRegex::WithoutSeparatorCharacters => {
r"
( # 1. file name (colons not allowed)
Expand Down Expand Up @@ -419,6 +433,7 @@ pub fn parse_grep_line(line: &str) -> Option<GrepLine> {
Some(process::CallingProcess::GitGrep(_))
| Some(process::CallingProcess::OtherGrep) => [
&*GREP_LINE_REGEX_ASSUMING_FILE_EXTENSION_AND_LINE_NUMBER,
&*GREP_LINE_REGEX_ASSUMING_FILE_EXTENSION_NO_SPACES,
&*GREP_LINE_REGEX_ASSUMING_FILE_EXTENSION,
&*GREP_LINE_REGEX_ASSUMING_NO_INTERNAL_SEPARATOR_CHARS,
]
Expand Down

0 comments on commit 2957f6f

Please sign in to comment.