Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid infinity loop in MatchIterator with zero-width match #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

omakoto
Copy link

@omakoto omakoto commented Sep 25, 2016

Hi, I found an issue with matches() that if the pattern matches an empty string, the next match will start from the same offset, ending up in an infinity loop.

In Perl, using a zero-width pattern with 'g' works as follows.

$ perl -e '$a = "12"; $a =~ s//x/g; print "$a\n"'
x1x2x

With this change, MatchIterator follows this behavior, so if the pattern matches an empty string, the next match will start from the next offset.

In Perl, using a zero-width patten with 'g' will not end up in
infinity loop.

$ perl -e '$a = '12'; $a =~ s//x/g; print "$a\n"'
x1x2x

Now MatchIterator follows this behavior, so if the pattern matches
zero-width string, the next match will start from the next position.
@omakoto
Copy link
Author

omakoto commented Oct 1, 2016

Hi, could you take a look? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant