Skip to content

Commit

Permalink
compilecode: Signify ^Q and $Q (Q is *, + or ?) as errors.
Browse files Browse the repository at this point in the history
^* and ^+ cause an "infinite loop" in the recursive, recursiveloop and
backtrack VMs. ^? and $* etc. are nonsense (if they are regarded as
assertions).

All of them raise "nothing to repeat" in Python3.

Also add tests.
  • Loading branch information
ampli committed Jul 24, 2015
1 parent d127f92 commit e5f770b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compilecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,12 @@ static const char *_compilecode(const char *re, ByteProg *prog, int sizecode)
case '^':
EMIT(PC++, Bol);
prog->len++;
term = PC;
break;
case '$':
EMIT(PC++, Eol);
prog->len++;
term = PC;
break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ test_suite = [
("search", "|+", ""),
("search", "|*", ""),
("search", "|?", ""),
("search", "^*", ""),
("search", "$*", ""),
]

import re
Expand Down

0 comments on commit e5f770b

Please sign in to comment.