ekmett/lens

Negative Index onto Text type results in returning first element

dvlasits opened this issue · 4 comments

The Text data structure returns the first element for all negative indices, when a negative index should be failing as per String I believe:

("123" :: String) ^? ix (-1)
Nothing

("123" :: Text) ^? ix (-1)
Just '1'

Yes, I agree. We should check if the index is between 0 and the length of the length of the Text, similarly to how we check this for things like Seq.

A similar problem affects the Ixed instances for ByteString types as well.

Yes sounds good, happy to try a PR on that front. It seems indices which are too large are handled correctly, so may only be necessary to check >= 0.

Fixed in #1030.

I've uploaded lens-5.2.2 to Hackage with the changes from #1030. Thanks again for the patch!