Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feature(urlKeyValue): not rewriting duplicate params in url #2522

Closed
wants to merge 1 commit into from

Conversation

joshkurz
Copy link
Contributor

parseKeyValue and toKeyValue can work with duplicates:
1) parseKeyValue looks for presence of obj[key]
2) detects and replaces obj[key] with [obj[key],val]
3) then pushes more duplicates if neccessary
4) toKeyValue decodes array correctly
5)(not changed) $location.search({param: 'key'}) still replaces if neccessary
6)(not changed) $location.search({param: ['key','key2']}) sets the url with duplicates

BREAKING CHANGE: the url parameter duplicates are not rewritten anymore.
This will only effect deeplinks. Deeplinks in current apps that depend on
rewriting the duplicates will break. The deeplinks should
be changes to appear how they should look after angular strips the duplicates.

@petebacondarwin
Copy link
Contributor

This is like the counterpart to #1921.

@petebacondarwin
Copy link
Contributor

  • Contributor signed CLA now or in the past (if you just signed, leave a comment here with your real name)
  • PR doesn't introduce new api
  • PR is approved by 2+ senior team members
  • Intentional breaking change (both):
    • Approved by 2+ senior team members
    • The breaking change is documented (including migration steps)
  • PR contains unit tests
  • PR contains documentation update (if suitable)
  • PR passes all tests on Travis (sanity)
  • PR passes all tests on ci.angularjs.org (cross-browser compatibility)
  • PR is rebased against recent master
  • PR is squashed into one commit per logical change
  • PR's commit messages are descriptive and allows us to autogenerate release notes (required commit message format)
  • All changes requested in review have been implemented

@petebacondarwin
Copy link
Contributor

@joshkurz:
Have you signed the CLA? Surely you have!
Since this has a breaking change we need sign off from the core team.
We will need the documentation (of $location) to be updated to explain this breaking change more clearly.
I would use the same breaking change comment vojta in this commit: 2a21234.

@joshkurz
Copy link
Contributor Author

@petebacondarwin yes I have signed the CLA.
I have already updated $location docs.

Its funny. This commit message kinda hints at this being buggy behavior, but your right volta hits it right on the head.

@penfold
Copy link

penfold commented Jun 24, 2013

@petebacondarwin Are you able to say when this change will reach master?

Thanks,
Paul

@petebacondarwin
Copy link
Contributor

This week hopefully

Pete
...from my mobile.
On 24 Jun 2013 09:35, "penfold" [email protected] wrote:

@petebacondarwin https://github.com/petebacondarwin Are you able to say
when this change will reach master?

Thanks,
Paul


Reply to this email directly or view it on GitHubhttps://github.com//pull/2522#issuecomment-19894945
.

@penfold
Copy link

penfold commented Jun 24, 2013

@petebacondarwin That is super!

Thanks,
Paul

@petebacondarwin
Copy link
Contributor

Just looking at this again, we have a bit of a problem when serializing query to a URL: There is no standard way to convert arrays to URL queries. It is server dependent.

For instance, in PHP (and Rails?) it expects the param name to be followed by [], e.g.

?names[]=misko&names[]=igor

This PR, and others that have been suggested, all want to simply repeat the query parameter in the string. Now this is not too bad since we can simply add the [] to the end of the param name is that is what is required by the server:

$location.search('names[]', ['misko', 'igor']);

But then when reading the search you would need to again provide the [] in the param name:

var names = $location.search('names[]');

Is this an acceptable situation?

@pkozlowski-opensource
Copy link
Member

@petebacondarwin I think we will have a hard time second-guess serialization (and parsing!) behavior of various back-ends. This is why I was proposing to do a (configurable / replacable) service for this. Such a service could be used by both $http and $location.

@petebacondarwin
Copy link
Contributor

Hi Pawel. Where did you get to with that? Is this current solution adequate
for the time being?
Pete

Pete
...from my mobile.
On 24 Jun 2013 11:17, "Pawel Kozlowski" [email protected] wrote:

@petebacondarwin https://github.com/petebacondarwin I think we will
have a hard time second-guess serialization (and parsing!) behavior of
various back-ends. This is why I was proposing to do a (configurable /
replacable) service for this. Such a service could be used by both $http
and $location.


Reply to this email directly or view it on GitHubhttps://github.com//pull/2522#issuecomment-19898909
.

@pkozlowski-opensource
Copy link
Member

@petebacondarwin I didn't implement anything in this respect, was just suggesting this solution in other PRs as the topic of serializing URL params comes back over and over again (as it touches $location, $http and $resource). Your proposal should work but it just feels a bit hacky.

I really think that a simple service with 2 methods (serialize, deserialize) would be simple to write and test. It should be an elegant solution.

@penfold
Copy link

penfold commented Jun 24, 2013

The service option sounds like a good solution.

I assume that a default service would be used? If so, which style would it use? My preference is to use plain param name (i.e. without []). (but I'm not worried as I am happy to swap in my own serialising service.)

@pkozlowski-opensource
Copy link
Member

@penfold yes, the idea would be to have a default service behaving in a way that code works as today. But people would be able to swap a service at will (and I'm sure that people would come up with services for specific back-ends and publish them to http://ngmodules.org/).

@petebacondarwin
Copy link
Contributor

Well actually the current version is broken so we have to change it at least a little.

@IgorMinar
Copy link
Contributor

This PR looks good to me (after all the small stuff I noted is fixed). The serialization schema is consistent with the one used by $http service.

I agree that having pluggable serialization mechanism would be better and we can do that in a separate PR.

Are there any unresolved design issues that prevent us from merging this in?

@joshkurz
Copy link
Contributor Author

Would there be any pushback on exposing the parseKeyValue and toKeyValue methods? They are nice functions that could be used in other instances.

parseKeyValue and toKeyValue can work with duplicates:
    1)parseKeyValue looks for presence of obj[key]
    2)detects and replaces obj[key] with [obj[key],val]
    3)then pushes more duplicates if neccessary
    4)toKeyValue decodes array correctly
    5)(not changed)$location.search({param: 'key'}) still replaces if neccessary
    6)(not changed)$location.search({param: ['key','key2']}) sets the url with duplicates

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 resource service.
@joshkurz
Copy link
Contributor Author

just updated the changes requested with a squashed version of the original commit.

@penfold @petebacondarwin @pkozlowski-opensource I agree with all of you that a service would be best here as well. Before we go this route, does it make sense to expose the parseKeyValue and toKeyValue methods from the Angular.js file? Then we can convert the logic to a urlUtls service or something along those lines.

@penfold
Copy link

penfold commented Jun 25, 2013

@joshkurz I'm somewhat split over the idea. On one side if the methods are made public then it would allow an initial refactor of all the duplicate code for handling keyValues to be made. But on the other hand why not do all the changes in one go?

@joshkurz
Copy link
Contributor Author

Ok your right. If we make the methods public, then this PR would extend it's original intent. The purpose here was to add the correct logic for duplicate params. Anything else should be taken care of in a subsequent PR.

Thanks
Josh Kurz (mobile)

----- Reply message -----
From: "penfold" [email protected]
To: "angular/angular.js" [email protected]
Cc: "Josh Kurz" [email protected]
Subject: [angular.js] feature(urlKeyValue): not rewriting duplicate params in url (#2522)
Date: Tue, Jun 25, 2013 2:57 AM
@joshkurz I'm somewhat split over the idea. On one side if the methods are made public then it would allow an initial refactor of all the duplicate code for handling keyValues to be made. But on the other hand why not do all the changes in one go?


Reply to this email directly or view it on GitHub.

@petebacondarwin
Copy link
Contributor

Agreed. Also we have think carefully about what we make public API since we have to support it going forward. Better to get this fix in now and then have time to think through the best solution going forward.

@penfold
Copy link

penfold commented Jun 25, 2013

Not wanting to sound pushy, but are we good to go with Josh's updated commit?

@shane-green
Copy link

Totally jumping in out of context here, but could the form fields actually be given names with “[]” in them, like ...
And have you tried using an associative array to do the same with serialized objects: values[“name[]”] = ....

If this actually has anything to do with what’s being discussed, then those approaches would turn it into a configuration matter.

(I’m also completely new to angular.js, so there’s another reason I may have just misinterpreted the discussion altogether.)

On Jun 24, 2013, at 4:33 AM, penfold [email protected] wrote:

The service option sounds like a good solution.

I assume that a default service would be used? If so, which style would it use? My preference is to use plain param name (i.e. without []). (but I'm not worried as I am happy to swap in my own serialising service.)


Reply to this email directly or view it on GitHub.

@penfold
Copy link

penfold commented Jun 29, 2013

@petebacondarwin @IgorMinar Can this PR be merged into master following @joshkurz's updated commit?

@petebacondarwin
Copy link
Contributor

Yep

Pete
...from my mobile.
On 29 Jun 2013 19:53, "penfold" [email protected] wrote:

@petebacondarwin https://github.com/petebacondarwin @IgorMinarhttps://github.com/IgorMinarCan this PR be merged into master following
@joshkurz https://github.com/joshkurz's updated commit?


Reply to this email directly or view it on GitHubhttps://github.com//pull/2522#issuecomment-20235086
.

@penfold
Copy link

penfold commented Jul 1, 2013

@petebacondarwin As this PR is ready, please will you merge it in? (I assume you are the right person to ask?)

@petebacondarwin
Copy link
Contributor

Trying to but our CI server has gone a bit pear shaped! Are you running
off master HEAD? I ask because, obviously, even after it is merged, it
will not appear in a release for a little while anyway. In the meantime
can you patch your own git?
Should be there on master within the next day or two anyway.

On 1 July 2013 14:48, penfold [email protected] wrote:

@petebacondarwin https://github.com/petebacondarwin As this PR is
ready, please will you merge it in? (I assume you are the right person to
ask?)


Reply to this email directly or view it on GitHubhttps://github.com//pull/2522#issuecomment-20282582
.

@penfold
Copy link

penfold commented Jul 1, 2013

Yes, I'm running off master. ( I got all excited about 1.2 and my delivery date isn't too close. I've got a patched fork but its just the overhead of maintaining it.

Looking forward to the next release.
Thanks,
Paul

@petebacondarwin
Copy link
Contributor

Finally, landed at 8073940! Thanks for the time and comments to move this through.

@penfold
Copy link

penfold commented Jul 1, 2013

@petebacondarwin @joshkurz Thanks for getting this fixed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants