Fixes #13843.
An empty regex is a valid regex that always matches. This behavior is consistent with at least Go and Python. A couple regression tests are included.
This commit is contained in:
@@ -201,6 +201,9 @@ pub fn parse(s: &str) -> Result<Ast, Error> {
|
|||||||
|
|
||||||
impl<'a> Parser<'a> {
|
impl<'a> Parser<'a> {
|
||||||
fn parse(&mut self) -> Result<Ast, Error> {
|
fn parse(&mut self) -> Result<Ast, Error> {
|
||||||
|
if self.chars.len() == 0 {
|
||||||
|
return Ok(Nothing);
|
||||||
|
}
|
||||||
loop {
|
loop {
|
||||||
let c = self.cur();
|
let c = self.cur();
|
||||||
match c {
|
match c {
|
||||||
|
|||||||
@@ -28,6 +28,20 @@ fn split() {
|
|||||||
assert_eq!(subs, vec!("cauchy", "plato", "tyler", "binx"));
|
assert_eq!(subs, vec!("cauchy", "plato", "tyler", "binx"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_regex_empty_match() {
|
||||||
|
let re = regex!("");
|
||||||
|
let ms = re.find_iter("").collect::<Vec<(uint, uint)>>();
|
||||||
|
assert_eq!(ms, vec![(0, 0)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_regex_nonempty_match() {
|
||||||
|
let re = regex!("");
|
||||||
|
let ms = re.find_iter("abc").collect::<Vec<(uint, uint)>>();
|
||||||
|
assert_eq!(ms, vec![(0, 0), (1, 1), (2, 2), (3, 3)]);
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! replace(
|
macro_rules! replace(
|
||||||
($name:ident, $which:ident, $re:expr,
|
($name:ident, $which:ident, $re:expr,
|
||||||
$search:expr, $replace:expr, $result:expr) => (
|
$search:expr, $replace:expr, $result:expr) => (
|
||||||
|
|||||||
Reference in New Issue
Block a user