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

Add tests for #9306 #9315

Closed
kaushalmodi opened this issue Oct 11, 2018 · 4 comments
Closed

Add tests for #9306 #9315

kaushalmodi opened this issue Oct 11, 2018 · 4 comments
Labels

Comments

@kaushalmodi
Copy link
Contributor

#9306 got fixed in 8ab6fa1 but tests need to be added.

@Araq
Copy link
Member

Araq commented Oct 11, 2018

What are the odds this pops up again? Close to zero, hence I didn't add tests.

@skilchen
Copy link
Contributor

skilchen commented Oct 11, 2018

Unfortunately 8ab6fa1 fixes only part of the issue #9306:

import re
echo replace("bar", re"^", "foo")
echo replace("foo", re"", "-")

both replacements still end in an infinite loop instead of producing:

foobar
-f-o-o-

and:

import re
echo "".replacef(re"([^\d]*)(\d*)([^\w]*)", "$1 - $2 - $3")

produces no output, but using nre and in other languages (Perl, Gawk, Python, JavaScript, ruby, elixir, erlang) equivalent code produces:

 - - 

i.e. 3 zero-length matches resulting in empty-string captures.

@Araq Araq closed this as completed Oct 14, 2018
@skilchen
Copy link
Contributor

Thanks for your work on this issue!
The good thing: there are no longer any infinite loops. Thats excellent, but:

import re
echo replace("foo", re"", "-")

produces:
-foo
While in the common understanding of regular expressions there is an empty string in front of any string, one between every substring of length 1 and one at the end of the string.
nre.nim produces the usually expected -f-o-o-
With nre as well as in the other languages I know the following is also possible:

import nre
echo replace("foo", re"^|$", "-")

which produces
-foo-
as expected, but using re you get: -foo which doesn't seem correct.

import re
echo "".replacef(re"([^\d]*)(\d*)([^\w]*)", "$1 - $2 - $3")

still produces an empty line, which doesn't seem correct, I would expect - -. However on a string that usually should be split using this pattern, it works:

import re
echo "abc123###".replacef(re"([^\d]*)(\d*)([^\w]*)", "$1 - $2 - $3")

correctly produces:
abc - 123 - ###

@Araq
Copy link
Member

Araq commented Oct 15, 2018

Now that you know by my commits how to fix/touch re.nim, feel free to submit PRs.

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

No branches or pull requests

4 participants