Don’t crash when the region is outside the underlying string.

This re-instates behaviour from before the API work.

Fixed #1002302