Negative Index onto Text type results in returning first element
dvlasits opened this issue · 4 comments
dvlasits commented
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'
RyanGlScott commented
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.
dvlasits commented
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.
RyanGlScott commented
Fixed in #1030.
RyanGlScott commented
I've uploaded lens-5.2.2
to Hackage with the changes from #1030. Thanks again for the patch!