Skip to content

Commit

Permalink
regex: The first range in a character class can start with a left bra…
Browse files Browse the repository at this point in the history
…cket
  • Loading branch information
pczarn committed Oct 24, 2014
1 parent 48daba0 commit f219773
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/libregex/parse.rs
Expand Up @@ -374,10 +374,6 @@ impl<'a> Parser<'a> {
let mut ranges: Vec<(char, char)> = vec!();
let mut alts: Vec<Ast> = vec!();

if self.peek_is(1, ']') {
try!(self.expect(']'));
ranges.push((']', ']'))
}
while self.peek_is(1, '-') {
try!(self.expect('-'));
ranges.push(('-', '-'))
Expand Down Expand Up @@ -411,7 +407,7 @@ impl<'a> Parser<'a> {
ast => fail!("Unexpected AST item '{}'", ast),
}
}
']' => {
']' if ranges.len() > 0 || alts.len() > 0 => {
if ranges.len() > 0 {
let flags = negated | (self.flags & FLAG_NOCASE);
let mut ast = AstClass(combine_ranges(ranges), flags);
Expand Down
7 changes: 7 additions & 0 deletions src/libregex/test/tests.rs
Expand Up @@ -53,6 +53,13 @@ fn quoted_bracket_set() {
assert_eq!(ms, vec![(0, 1), (1, 2)]);
}

#[test]
fn first_range_starts_with_left_bracket() {
let re = regex!(r"([[-z])");
let ms = re.find_iter("[]").collect::<Vec<(uint, uint)>>();
assert_eq!(ms, vec![(0, 1), (1, 2)]);
}

#[test]
fn range_ends_with_escape() {
let re = regex!(r"([\[-\x{5d}])");
Expand Down

9 comments on commit f219773

@bors
Copy link
Contributor

@bors bors commented on f219773 Oct 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from burntsushi
at pczarn@f219773

@bors
Copy link
Contributor

@bors bors commented on f219773 Oct 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pczarn/rust/regex-parse = f219773 into auto

@bors
Copy link
Contributor

@bors bors commented on f219773 Oct 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pczarn/rust/regex-parse = f219773 merged ok, testing candidate = aa0023cf

@bors
Copy link
Contributor

@bors bors commented on f219773 Oct 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on f219773 Oct 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from burntsushi
at pczarn@f219773

@bors
Copy link
Contributor

@bors bors commented on f219773 Oct 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pczarn/rust/regex-parse = f219773 into auto

@bors
Copy link
Contributor

@bors bors commented on f219773 Oct 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pczarn/rust/regex-parse = f219773 merged ok, testing candidate = 4769bca

@bors
Copy link
Contributor

@bors bors commented on f219773 Oct 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on f219773 Oct 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 4769bca

Please sign in to comment.