Fix issue 2048: Handle the -1 problem of indexOf function