Difference between decodeURIComponent and decodeURI

Различия в decodeURI и decodeURIComponent, в последнем нет исключений он декодирует все символы.
tt1 = encodeURI(" ; / ? : @ & = + $ , # ")
"%20;%20/%20?%20:%20@%20&%20=%20+%20$%20,%20#%20"
tt2 = encodeURIComponent(" ; / ? : @ & = + $ , # ")
"%20%3B%20%2F%20%3F%20%3A%20%40%20%26%20%3D%20%2B%20%24%20%2C%20%23%20"
tt3 = decodeURI(tt1)
" ; / ? : @ & = + $ , # "
tt4 = decodeURI(tt2)
" %3B %2F %3F %3A %40 %26 %3D %2B %24 %2C %23 "
tt5 = decodeURIComponent(tt1)
" ; / ? : @ & = + $ , # "
tt6 = decodeURIComponent(tt2)
" ; / ? : @ & = + $ , # "
const jschar js_uriReservedPlusPound_ucstr[] =
    {';', '/', '?', ':', '@', '&', '=', '+', '$', ',', '#', 0};

static JSBool
str_decodeURI(JSContext *cx, uintN argc, jsval *vp) {
    JSString *str;

    str = ArgToRootedString(cx, argc, vp, 0);
    if (!str)
        return JS_FALSE;
    return Decode(cx, str, js_uriReservedPlusPound_ucstr, vp);
}

static JSBool
str_decodeURI_Component(JSContext *cx, uintN argc, jsval *vp) {
    JSString *str;

    str = ArgToRootedString(cx, argc, vp, 0);
    if (!str)
        return JS_FALSE;
    return Decode(cx, str, js_empty_ucstr, vp);
}

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *