This doesn't handle the case where str is undefined, same with unescape