Skip to content
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

Stable encoded parameter order for URLEncodedFormEncoder #2961

Merged
merged 13 commits into from
Oct 19, 2019

Conversation

jshier
Copy link
Contributor

@jshier jshier commented Oct 7, 2019

Issue Link 🔗

#2957

Goals ⚽

This PR refactors the implementation of URLEncodedFormEncoder to make the parameter encoding consistent between runs.

Implementation Details 🚧

This PR swaps the previous Dictionary storage in URLEncodedFormComponent's object case for a [(key: String, value: URLEncodedFormComponent)], allowing for a constant order at runtime. Additionally, an alphabetizeKeyValuePairs parameter was added to URLEncodedFormEncoder which controls the sorting of encoded components as they're serialized into the final String.

This PR also turns off SWIFT_DETERMINISTIC_HASHING to ensure we're testing with randomized Dictionary ordering. Due to this PR it's no longer necessary to have it turned on.

Testing Details 🔍

Tests were updated for new expected ordering and to expect exact matches.

@jshier jshier mentioned this pull request Oct 7, 2019
1 task
Copy link
Member

@cnoon cnoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me @jshier. I just had one callout on one of the docstrings.

Comment on lines 303 to 307
/// Whether or not to sort the encoded key value pairs.
///
/// - Note: This setting ensures a consistent ordering for all encodings of the same parameters. When set to `false`,
/// encoded `Dictionary` values may have a different encoded order each time they're encoded due to
/// ` Dictionary`'s random storage order.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this Note is a bit outdated since you've switched over to a tuple array. Isn't it now going to be either the order the parameters were provided or alphabetically sorted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this note refers to Dictionarys being encoded, which will still have a variable order between app launches. Let me know if there’s a better way to say that here.

@jshier jshier merged commit 9187007 into master Oct 19, 2019
@jshier jshier deleted the bug/urlencodedform-stable-parameter-ordering branch October 19, 2019 23:00
@jshier jshier added this to the 5.0.0-rc.3 milestone Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants