Fix unsafe string slicing in ShouldStartsWith/ShouldEndsWith.