* Updated the regex crate to 0.2.2 as per issue #88 * Added potential fix for cryptic CI error. * Fixed incorrect handling of regex name call. Fixes #88
This commit is contained in:
committed by
Jakob Stoklund Olesen
parent
c1d095de18
commit
de0f0e5f0a
@@ -11,4 +11,4 @@ documentation = "https://docs.rs/filecheck"
|
|||||||
name = "filecheck"
|
name = "filecheck"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
regex = "0.1.71"
|
regex = "0.2.2"
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ const DIRECTIVE_RX: &str = r"\b(check|sameln|nextln|unordered|not|regex):\s+(.*)
|
|||||||
impl Directive {
|
impl Directive {
|
||||||
/// Create a new directive from a `DIRECTIVE_RX` match.
|
/// Create a new directive from a `DIRECTIVE_RX` match.
|
||||||
fn new(caps: Captures) -> Result<Directive> {
|
fn new(caps: Captures) -> Result<Directive> {
|
||||||
let cmd = caps.at(1).expect("group 1 must match");
|
let cmd = caps.get(1).map(|m| m.as_str()).expect("group 1 must match");
|
||||||
let rest = caps.at(2).expect("group 2 must match");
|
let rest = caps.get(2).map(|m| m.as_str()).expect("group 2 must match");
|
||||||
|
|
||||||
if cmd == "regex" {
|
if cmd == "regex" {
|
||||||
return Directive::regex(rest);
|
return Directive::regex(rest);
|
||||||
@@ -208,11 +208,12 @@ impl Checker {
|
|||||||
// Verify any pending `not:` directives now that we know their range.
|
// Verify any pending `not:` directives now that we know their range.
|
||||||
for (not_idx, not_begin, rx) in nots.drain(..) {
|
for (not_idx, not_begin, rx) in nots.drain(..) {
|
||||||
state.recorder.directive(not_idx);
|
state.recorder.directive(not_idx);
|
||||||
if let Some((s, e)) = rx.find(&text[not_begin..match_begin]) {
|
if let Some(mat) = rx.find(&text[not_begin..match_begin]) {
|
||||||
// Matched `not:` pattern.
|
// Matched `not:` pattern.
|
||||||
state
|
state
|
||||||
.recorder
|
.recorder
|
||||||
.matched_not(rx.as_str(), (not_begin + s, not_begin + e));
|
.matched_not(rx.as_str(),
|
||||||
|
(not_begin + mat.start(), not_begin + mat.end()));
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
} else {
|
} else {
|
||||||
state
|
state
|
||||||
@@ -337,23 +338,23 @@ impl<'a> State<'a> {
|
|||||||
} else {
|
} else {
|
||||||
// We need the captures to define variables.
|
// We need the captures to define variables.
|
||||||
rx.captures(txt).map(|caps| {
|
rx.captures(txt).map(|caps| {
|
||||||
let matched_range = caps.pos(0).expect("whole expression must match");
|
let matched_range = caps.get(0).expect("whole expression must match");
|
||||||
for var in defs {
|
for var in defs {
|
||||||
let txtval = caps.name(var).unwrap_or("");
|
let txtval = caps.name(var).map(|mat| mat.as_str()).unwrap_or("");
|
||||||
self.recorder.defined_var(var, txtval);
|
self.recorder.defined_var(var, txtval);
|
||||||
let vardef = VarDef {
|
let vardef = VarDef {
|
||||||
value: Value::Text(Cow::Borrowed(txtval)),
|
value: Value::Text(Cow::Borrowed(txtval)),
|
||||||
// This offset is the end of the whole matched pattern, not just the text
|
// This offset is the end of the whole matched pattern, not just the text
|
||||||
// defining the variable.
|
// defining the variable.
|
||||||
offset: range.0 + matched_range.1,
|
offset: range.0 + matched_range.end(),
|
||||||
};
|
};
|
||||||
self.vars.insert(var.clone(), vardef);
|
self.vars.insert(var.clone(), vardef);
|
||||||
}
|
}
|
||||||
matched_range
|
matched_range
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
Ok(if let Some((b, e)) = matched_range {
|
Ok(if let Some(mat) = matched_range {
|
||||||
let r = (range.0 + b, range.0 + e);
|
let r = (range.0 + mat.start(), range.0 + mat.end());
|
||||||
self.recorder.matched_check(rx.as_str(), r);
|
self.recorder.matched_check(rx.as_str(), r);
|
||||||
Some(r)
|
Some(r)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use error::{Error, Result};
|
|||||||
use variable::{varname_prefix, VariableMap, Value};
|
use variable::{varname_prefix, VariableMap, Value};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::fmt::{self, Display, Formatter, Write};
|
use std::fmt::{self, Display, Formatter, Write};
|
||||||
use regex::{Regex, RegexBuilder, quote};
|
use regex::{Regex, RegexBuilder, escape};
|
||||||
|
|
||||||
/// A pattern to match as specified in a directive.
|
/// A pattern to match as specified in a directive.
|
||||||
///
|
///
|
||||||
@@ -313,7 +313,7 @@ impl Pattern {
|
|||||||
for part in &self.parts {
|
for part in &self.parts {
|
||||||
match *part {
|
match *part {
|
||||||
Part::Text(ref s) => {
|
Part::Text(ref s) => {
|
||||||
out.push_str("e(s));
|
out.push_str(&escape(s));
|
||||||
}
|
}
|
||||||
Part::Regex(ref rx) => out.push_str(rx),
|
Part::Regex(ref rx) => out.push_str(rx),
|
||||||
Part::Var(ref var) => {
|
Part::Var(ref var) => {
|
||||||
@@ -322,7 +322,7 @@ impl Pattern {
|
|||||||
None => {
|
None => {
|
||||||
return Err(Error::UndefVariable(format!("undefined variable ${}", var)))
|
return Err(Error::UndefVariable(format!("undefined variable ${}", var)))
|
||||||
}
|
}
|
||||||
Some(Value::Text(s)) => out.push_str("e(&s)),
|
Some(Value::Text(s)) => out.push_str(&escape(&s)),
|
||||||
// Wrap regex in non-capturing group for safe concatenation.
|
// Wrap regex in non-capturing group for safe concatenation.
|
||||||
Some(Value::Regex(rx)) => write!(out, "(?:{})", rx).unwrap(),
|
Some(Value::Regex(rx)) => write!(out, "(?:{})", rx).unwrap(),
|
||||||
}
|
}
|
||||||
@@ -335,7 +335,7 @@ impl Pattern {
|
|||||||
None => {
|
None => {
|
||||||
return Err(Error::UndefVariable(format!("undefined variable ${}", var)))
|
return Err(Error::UndefVariable(format!("undefined variable ${}", var)))
|
||||||
}
|
}
|
||||||
Some(Value::Text(s)) => write!(out, "{})", quote(&s[..])).unwrap(),
|
Some(Value::Text(s)) => write!(out, "{})", escape(&s[..])).unwrap(),
|
||||||
Some(Value::Regex(rx)) => write!(out, "{})", rx).unwrap(),
|
Some(Value::Regex(rx)) => write!(out, "{})", rx).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -353,7 +353,7 @@ impl Pattern {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(RegexBuilder::new(&out).multi_line(true).compile()?)
|
Ok(RegexBuilder::new(&out).multi_line(true).build()?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user