-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avoid rearrange query parameters #926
Comments
Please be more specific about the problem you are facing. Query parameters are actually Key-value pairs, so they don't have the notion of 'order'. If your code depends on their order (which they don't have), you're probably doing it wrong. |
For example: when generating token,a full url path is needed.After token generated and return, the third-party platform will verify the consistency of url. |
|
谢谢您的回答,我知道该怎么调整了。 |
That is obviously intention!!! About this issue, besides, we discussed a lot in weibo: In such case,we very much regret that we can`t use dynamic segments instead of queries... |
@miccycn Oops, missed that part. Even if vue-router stopped sorting query keys, currently it still can't reliably preserve the initial order. It will have to remember the initial query to do so. I don't have a weibo account, would you mind posting the discussion here? I'm very curious about the case where dynamic segments can't be used. |
This case is so complicated...... 刘巍峰: I have tried to delete |
I don't see any reason dynamic segments cannot be used in the discussion.. Just deleting |
删了 可能是我们哪些细节地方还没考虑到。你说的会出问题是比如哪些情况呢?之前因为没重排而出现 issue 的 case 我可以看看么? 动态路由匹配需要更改和加入新的路由,而且由于微博的业务复杂,要加的新路由数量也指数增加,不仅后端要跟着新加,我们之前使用的url也会作废。 |
就像Evan之前说的一样,各个平台顺序是不能保证的,因为ECMA标准没有规定Object.keys()返回的顺序,全部依靠浏览器实现。{a:1, b:2, c:3}的遍历顺序可以是c, b, a,这是完全合法的。 跟Object一样,query string本身的设计就是键值对,没有顺序这个概念。RFC标准和W3C标准都没有规定对于所谓"顺序"的处理。对于当初设计成依赖query“顺序”的已有系统,那实在是比较遗憾。 不过,如果你们只考虑中国网民常用浏览器的话,也倒是可以删掉这个sort。因为大部分人不依赖query的“顺序”(也不应该依赖,任何有顺序的参数都应该使用dynamic segments),所以并不是一个breaking change。但还是要重申一下,这不能保证你的url在所有情况下一定能正常工作。保险的做法是记住上一个query的顺序,下一次序列化的时候按照这个顺序来。总之,欢迎提交PR。 |
唉……这没办法,中国最大的两个网络社交媒体平台:微博和微信,都设计成了依赖query顺序了。 但是是否可以这么理解,不 我提交过PR: |
把那个测试项删掉就可以了。因为它是针对sort()的测试,不sort了就可以删掉咯。提PR的时候不用担心修改测试的问题,因为都是会经过review的 🙂
分享个网页还需要拿url去签名真的是中国特色,纯粹是用来恶心开发者的。单从签名的角度上说,url要保持一致(包括query的顺序)是可以理解的。所以为了适应这个需要签名的系统,开发应用的时候url用dynamic segments传参保持顺序是最稳妥的做法。因为query参数谁都可以随便改(比如微信会加个'from'之类的),而且没有标准规定要遵守原来的顺序。 |
唉……大坑慎入…… |
Avoid rearrange query parameters.
Sorting and rearranging them will cost a new request,and make some troubles like generating token which is based on query string.
The issue is in:
util/query.js
function stringifyQuery()
unacquainted with jasmine :(
The text was updated successfully, but these errors were encountered: