-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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: Add brackets to querystring to clarify it's array (#1672) #1673
base: master
Are you sure you want to change the base?
Conversation
If length of array is 1, it was being recognized as a string, not an array. - AS-IS: { colors: ['black', 'mustard'] } -> colors=black&colors=mustard { colors: ['black'] } -> colors=black - TO-BE: { colors: ['black', 'mustard'] } -> colors[]=black&colors[]=mustard { colors: ['black'] } -> colors[]=black Added qs dependency for this fix.
Codecov Report
@@ Coverage Diff @@
## master #1673 +/- ##
=======================================
Coverage 99.60% 99.60%
=======================================
Files 5 5
Lines 507 507
Branches 142 142
=======================================
Hits 505 505
Misses 2 2
Continue to review full report at Codecov.
|
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 for this change, however I fear this can break a lot of applications because users might rely on current behaviour today. I wouldn't be comfortable releasing this under Koa 2.x
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.
LGTM
Seems like a decent change but I'm going to let other maintainers decide on this one.
Is anyone willing to merge this PR? |
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.
@miwnwski From my side, in theory yes we can merge this PR now since we are on v3-alpha.
But we need to make it flexible because we have many strategies here and we don't push one over the other, let's prevent breaking changes
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' })
// 'a[0]=b&a[1]=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' })
// 'a[]=b&a[]=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })
// 'a=b&a=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'comma' })
// 'a=b,c'
cc: @fengmk2 🤔?!
Please can we not introduce The "bug" that this is fixing doesn't really seem like a problem to me. I think it's reasonable to assume that |
If length of array is 1, it was being recognized as a string, not an array.
{ colors: ['black', 'mustard'] } -> colors=black&colors=mustard
{ colors: ['black'] } -> colors=black
{ colors: ['black', 'mustard'] } -> colors[]=black&colors[]=mustard
{ colors: ['black'] } -> colors[]=black
Added qs dependency for this fix.
Checklist