This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix($http): config.param should expand array values properly
Today, calling e.g. $http(url, { params: { a: [1,2,3] } }) results in a query string like "?a=%5B1%2C2%2C3%5D" which is undesirable. This commit enhances buildURL to createa query string like "?a=1&a=2&a=3". BREAKING CHANGE: if the server relied on the buggy behavior then either the backend should be fixed or a simple serialization of the array should be done on the client before calling the $http service. Closes #1363
- Loading branch information
79af2ba
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.
Why did you decided not to follow jQuery's
$.param
logic for this parsing? Backends like Rails expect keys multiple values to end with[]
to indicate it's an array and jQuery$.param
does it correctly.Better yet, did you consider exposing an overridable default in
$httpProvider.defaults
, in a way that the user of the library could override this behavior depending on how the backend expects it to be handled? Would that be a good addition?79af2ba
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.
Largely because the spec already says I can have multiple query arguments with the same name and those should result in multiple values downstream. Proprietary extensions on top of that to make query argument parsing easier or more obvious as to the value type or whatever is a bad default. If you want
a[]
as your array (in this example) then simply pass{ 'a[]': [1, 2, 3] }
.79af2ba
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.
Thanks for the explanation @tdavis
79af2ba
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.
This is what I am looking for. Anything underway? Otherwise I'll have a try as soon as I find the time.
79af2ba
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.
Sorry if this is the wrong place to ask, but I was just curious when (roughly) this might make it's way into the stable release? New to angular and just as unfamiliar with the dev cycle. I tried this on stable 1.0.7 and this fix didn't seem to be implemented. Testing on 1.1.5 however, worked like a charm.