js-cookie 没有编码与 php setcookie 相同的值
js-cookie is not encoding the value the same as php setcookie
当我使用这个 https://github.com/js-cookie/js-cookie
创建 cookie 时
这是我的 crypt 变量内容..
s192aBszcV7NPrR8KpQbl4u/hkOOmMBzPg2mAhGlZB1/nAcus=0
然后用 js-cookie
..
设置 cookie
Cookies.set('_siteauth',crypt, {
expires: 1,
path: '/'
});
这是js设置的cookie值...
s192aBszcV7NPrR8KpQbl4u/hkOOmMBzPg2mAhGlZB1/nAcus=0
因此,如果我使用 php setcookie..
设置相同的变量
setcookie('_siteauth', $crypt, time() + 86400, '/');
cookie 的值是这个..
s192aBszcV7NPrR8KpQbl4u%2FhkOOmMBzPg2mAhGlZB1%2FnAcus%3D
我希望 cookie 值应该是这样的。已编码。
但是 js-cookie
关于编码的文档说这个 https://github.com/js-cookie/js-cookie#encoding,令我惊讶的是 set js-cookie 的值根本没有被编码。
任何人都可以解释一下吗,或者我在 js-cookie
插件中遗漏了什么?
正如 js-cookie documentation 所说:
This project is RFC 6265 compliant. All special characters that are not allowed in the cookie-name or cookie-value are encoded with each one's UTF-8 Hex equivalent using percent-encoding.
[...]
Please note that the default encoding/decoding strategy is meant to be interoperable only between cookies that are read/written by js-cookie. To override the default encoding/decoding strategy you need to use a converter.
(强调我的。)
根据 RFC 6265,cookie 值可以包含集合 !#$%&'()*+-./:<=>?@[]^_`{|}~
中的任何字符以及数字 (0-9
) 和字母 (a-zA-Z
)。
请注意,/
和 =
都是 cookie 值中的有效字符。
此外,未指定编码或转义机制:
The semantics of the cookie-value are not defined by this document.
To maximize compatibility with user agents, servers that wish to
store arbitrary data in a cookie-value SHOULD encode that data, for
example, using Base64 [RFC4648].
percent-encoding 对 cookie 值的使用未标准化。不同的库为 cookie 值提出不同的编码方案也就不足为奇了。特别是,js-cookie 不是为了兼容任何编码方案而设计的,而是它自己的。
当我使用这个 https://github.com/js-cookie/js-cookie
创建 cookie 时这是我的 crypt 变量内容..
s192aBszcV7NPrR8KpQbl4u/hkOOmMBzPg2mAhGlZB1/nAcus=0
然后用 js-cookie
..
Cookies.set('_siteauth',crypt, {
expires: 1,
path: '/'
});
这是js设置的cookie值...
s192aBszcV7NPrR8KpQbl4u/hkOOmMBzPg2mAhGlZB1/nAcus=0
因此,如果我使用 php setcookie..
setcookie('_siteauth', $crypt, time() + 86400, '/');
cookie 的值是这个..
s192aBszcV7NPrR8KpQbl4u%2FhkOOmMBzPg2mAhGlZB1%2FnAcus%3D
我希望 cookie 值应该是这样的。已编码。
但是 js-cookie
关于编码的文档说这个 https://github.com/js-cookie/js-cookie#encoding,令我惊讶的是 set js-cookie 的值根本没有被编码。
任何人都可以解释一下吗,或者我在 js-cookie
插件中遗漏了什么?
正如 js-cookie documentation 所说:
This project is RFC 6265 compliant. All special characters that are not allowed in the cookie-name or cookie-value are encoded with each one's UTF-8 Hex equivalent using percent-encoding.
[...]
Please note that the default encoding/decoding strategy is meant to be interoperable only between cookies that are read/written by js-cookie. To override the default encoding/decoding strategy you need to use a converter.
(强调我的。)
根据 RFC 6265,cookie 值可以包含集合 !#$%&'()*+-./:<=>?@[]^_`{|}~
中的任何字符以及数字 (0-9
) 和字母 (a-zA-Z
)。
请注意,/
和 =
都是 cookie 值中的有效字符。
此外,未指定编码或转义机制:
The semantics of the cookie-value are not defined by this document.
To maximize compatibility with user agents, servers that wish to store arbitrary data in a cookie-value SHOULD encode that data, for example, using Base64 [RFC4648].
percent-encoding 对 cookie 值的使用未标准化。不同的库为 cookie 值提出不同的编码方案也就不足为奇了。特别是,js-cookie 不是为了兼容任何编码方案而设计的,而是它自己的。