This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ngResource): don't convert literal values into Resource objects w…
…hen isArray is true Previously non-object literals would be thrown out of Resource responses with isArray===true, or otherwise converted into Objects (in the case of string literals). The reason for this is because shallowClearAndCopy iterates over keys, and copies keys into the destination. Iterating over String keys results in integer keys, with a single-character value. Not converting non-objects to Resources means that you lose the ability to perform Resource operations on them. However, they become usable as strings, numbers, or booleans, which is important. In the future, it would be useful to make these useful as Resources while still retaining their primitive value usefulness. Closes #6314 Closes #7741
- Loading branch information
1 parent
81b7e5a
commit f0904cf
Showing
2 changed files
with
37 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f0904cf
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.
Are you sure that was this commit? because this isn't related to URL serialization, this is literally only for creating Resource objects from responses --- nothing to do with requests
f0904cf
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.
You're right. I don't see this transformation happening in ngResource. I thought I did yesterday, but realized that isArrayLike(obj) (angular.js:264) was considering my string literal to be array like. This in turn was causing angular.forEach (angular.js:308) to run iterator.call(context, obj[key], key) on my literal. Which then passes 0=E&1=H&2=A&3=C&4=W&5=F&6=5&7=H&8=W&9=C instead of token="EHACWF5HWC" in the dst object through angular.extend (angular.js:422) to my $resource param.
I initially thought this commit to be the culprit since it was the only one I could find between last Friday and this Monday (edit: I now notice this was committed 11 days ago). However, hardcoding the value of token in the $resource call worked when passing it as a value from the controller did not. Which is why I deleted my comment yesterday. I cannot find what change is making my parameter pass as an array instead of a key, value object, but it has completely shut down my development. I guess my next step is to create a test project that I can share with fresh files to see if I can recreate my issue.
Regards and apologies,
Owen
f0904cf
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.
UPDATE: The problem was completely on my end. My controller's code calling the api changes and was passing just the literal instead of telling which parameter to assign the value.
i.e.
api.Trip.get(data.token)
- Incorrectapi.Trip.get({token: data.token})
- Correct.Although, this presents an interesting problem (feature?). A string literal passed as an argument to $resource ends up at the end of the templated url in an array after a '?'.
Thus,
api/trip/EHACWF5HWC
becomes
api/trip?0=E&1=H&2=A&3=C&4=W&5=F&6=5&7=H&8=W&9=C
Regards,
Owen