Fix JS string range end handling