Improve isUrlEncoded and prevent infinite loop in urlDecode