-
-
Notifications
You must be signed in to change notification settings - Fork 735
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
Fix depth: 0
, add depth: false
#326
Conversation
Google translate says the title is: "Add a rule for depth==0", and the body:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dist folder is generated, so no changes should ever be made in it. Please make the changes inside lib.
Separately, please provide test cases for this new behavior. Is this a bugfix, or a new feature? I can't tell.
…ent and intuitive/intended
hello |
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { depth: 0 }), { 'a[0]': 'b', 'a[1]': 'c' }); | ||
st.deepEqual(qs.parse('a[0][0]=b&a[0][1]=c&a[1]=d&e=2', { depth: 0 }), { 'a[0][0]': 'b', 'a[0][1]': 'c', 'a[1]': 'd', e: '2' }); | ||
st.end(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
补充了上面的测试
我觉得这是一个新规则
edit (ljharb): translation added
Added the above test
I think this is a new rule.
I think what we need here is to first add a bunch of tests on master with |
I am sorry. |
… should preserve the original key
I've updated this into two commits; the first that test the current behavior, and the second that make a I'm split on the semver of this. I could consider it a bugfix, since |
depth: 0
, add depth: false
Since I'm adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to go with this one being semver-minor.
If, in fact, someone has found a use case for the current depth: 0
behavior and this breaks them, I may revert that bugfix in the future - but depth: false
will remain regardless.
const Req = {
defaults: {
baseUrl: '',
headers: {},
qsOptions: { arrayFormat: 'indices', encodeValuesOnly: true },
},
base(method, url, data, header, extend) {
return new Promise((success, fail) => {
wx.request(Object.assign({ method, header, url, data, success, fail }, extend));
});
},
post(url, data) {
url = this.defaults.baseUrl + url;
data = qs.parse(qs.stringify(data, this.defaults.qsOptions), { depth: 0 });
let header = this.defaults.headers;
return this.base('post', url, data, header).then(res => {
if (res.statusCode == 200) {
if (res.data.code == 200) return res.data.data;
return Promise.reject(res.data.message);
}
return Promise.reject('接口请求失败');
});
},
get(url, data) {
url = this.defaults.baseUrl + url;
data = qs.parse(qs.stringify(data, this.defaults.qsOptions), { depth: 0 });
let header = this.defaults.headers;
return this.base('get', url, data, header).then(res => {
if (res.statusCode == 200) {
if (res.data.code == 200) return res.data.data;
return Promise.reject(res.data.message);
}
return Promise.reject('接口请求失败');
});
},
};
Req.get('/kan/article', { ids:[1,2,3,4,5] }) $ids = $request->input('ids',[]); I use it in WeChat applet development. |
@idler8 can you file a new issue with this? |
@ljharb Edit: this PR now adds tests for the current useless behavior of depth 0, and then fixes it. Fixes #261.
测试已经通过
我觉得这可以作为一个补充规则