google / starlark-go

Starlark in Go: the Starlark configuration language, implemented in Go
BSD 3-Clause "New" or "Revised" License
2.34k stars 212 forks source link

index (and rindex) do not advance sufficiently when calling with "" #134

Open josharian opened 5 years ago

josharian commented 5 years ago
$ python2 -c "print('a'.index('', 50))"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError: substring not found
(exit 1)

$ python3 -c "print('a'.index('', 50))"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError: substring not found
(exit 1)

$ starlark-go -c "print('a'.index('', 50))"
1
(exit 0)

Definitely a corner case: only occurs when searching for the empty string and the occurrence requested is higher than the length of the input string.

josharian commented 5 years ago

Another variant:

$ python2 -c "'a'.index('', 1, 0)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError: substring not found
(exit 1)

$ python3 -c "'a'.index('', 1, 0)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError: substring not found
(exit 1)

$ starlark-go -c "'a'.index('', 1, 0)"
(exit 0)

I have a fix for the original issue but not this second one. Will continue later.

alandonovan commented 5 years ago

Care to send a CL?

josharian commented 5 years ago

Yes. I haven't forgotten about starlark, it just got backburnered for a bit as I struggle with go-fuzz and go/packages. I'll circle around at some point and work on this and other things I've promised to do. If there's anything urgent, please let me know.