fix index-out-of-range bug in hasPrefix