You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rust-ripgrep/0001-grep-upgrade-to-regex-...

84 lines
2.7 KiB

From cd08707c7c82058559bd5557efb3c1d0379dbf1d Mon Sep 17 00:00:00 2001
From: Andrew Gallant <jamslam@gmail.com>
Date: Tue, 13 Mar 2018 20:38:50 -0400
Subject: [PATCH] grep: upgrade to regex-syntax 0.5
This update brings with it many bug fixes:
* Better error messages are printed overall. We also include
explicit call out for unsupported features like backreferences
and look-around.
* Regexes like `\s*{` no longer emit incomprehensible errors.
* Unicode escape sequences, such as `\u{..}` are now supported.
For the most part, this upgrade was done in a straight-forward way. We
resist the urge to refactor the `grep` crate, in anticipation of it
being rewritten anyway.
Note that we removed the `--fixed-strings` suggestion whenever a regex
syntax error occurs. In practice, I've found that it results in a lot of
false positives, and I believe that its use is not as paramount now that
regex parse errors are much more readable.
Closes #268, Closes #395, Closes #702, Closes #853
---
src/args.rs | 13 ++-----------
tests/tests.rs | 10 ----------
2 files changed, 2 insertions(+), 21 deletions(-)
diff --git a/src/args.rs b/src/args.rs
index c7b31dd3646e..2bbabf1a3b76 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -9,7 +9,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use clap;
use encoding_rs::Encoding;
-use grep::{Grep, GrepBuilder, Error as GrepError};
+use grep::{Grep, GrepBuilder};
use log;
use num_cpus;
use regex;
@@ -882,16 +882,7 @@ impl<'a> ArgMatches<'a> {
if let Some(limit) = self.regex_size_limit()? {
gb = gb.size_limit(limit);
}
- gb.build().map_err(|err| {
- match err {
- GrepError::Regex(err) => {
- let s = format!("{}\n(Hint: Try the --fixed-strings flag \
- to search for a literal string.)", err.to_string());
- From::from(s)
- },
- err => From::from(err)
- }
- })
+ Ok(gb.build()?)
}
/// Builds the set of glob overrides from the command line flags.
diff --git a/tests/tests.rs b/tests/tests.rs
index 8cb871843851..855f2484ddd3 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -1687,16 +1687,6 @@ sherlock!(feature_419_zero_as_shortcut_for_null, "Sherlock", ".",
assert_eq!(lines, "sherlock\x002\n");
});
-// See: https://github.com/BurntSushi/ripgrep/issues/709
-clean!(suggest_fixed_strings_for_invalid_regex, "foo(", ".",
-|wd: WorkDir, mut cmd: Command| {
- wd.assert_non_empty_stderr(&mut cmd);
-
- let output = cmd.output().unwrap();
- let err = String::from_utf8_lossy(&output.stderr);
- assert_eq!(err.contains("--fixed-strings"), true);
-});
-
#[test]
fn compressed_gzip() {
if !cmd_exists("gzip") {
--
2.14.3