-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Conversation
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.
Looks good to me @jshier. I just had one callout on one of the docstrings.
Source/URLEncodedFormEncoder.swift
Outdated
/// 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. |
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 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?
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.
No, this note refers to Dictionary
s 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.
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 inURLEncodedFormComponent
'sobject
case for a[(key: String, value: URLEncodedFormComponent)]
, allowing for a constant order at runtime. Additionally, analphabetizeKeyValuePairs
parameter was added toURLEncodedFormEncoder
which controls the sorting of encoded components as they're serialized into the finalString
.This PR also turns off
SWIFT_DETERMINISTIC_HASHING
to ensure we're testing with randomizedDictionary
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.