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

Safe URL encoding #38

Merged
merged 9 commits into from
May 15, 2023
Merged

Safe URL encoding #38

merged 9 commits into from
May 15, 2023

Conversation

kwasniew
Copy link
Contributor

@kwasniew kwasniew commented May 12, 2023

About the changes

  • make sure Unleash URL is correct before we proceed
  • Use URL in poller instead of string as it's more type safe
  • closes URL parameters are not encoded #32
  • version bump in podspec

Important files

Discussion points

@@ -41,19 +41,6 @@ final class PollerTests: XCTestCase {
XCTAssertEqual(poller.etag, "W/\"7c-GUwjw43L+nPpd9TY5PHtsXJueiM\"")
}

func testStartCompletesWithUrlError() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this scenario is impossible now

@@ -40,19 +40,22 @@ public class UnleashClientBase {
var metrics: Metrics

public init(unleashUrl: String, clientKey: String, refreshInterval: Int = 15, metricsInterval: Int = 30, disableMetrics: Bool = false, appName: String = "unleash-swift-client", environment: String? = nil, poller: Poller? = nil, metrics: Metrics? = nil) {
guard let url = URL(string: unleashUrl), url.scheme != nil else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sure URL passed to the client is correct so that we eliminate impossible URLs down the line

return unleashUrl + "?" + params.joined(separator: "&")
func formatURL(context: [String: String]) -> URL? {
var components = URLComponents(url: unleashUrl, resolvingAgainstBaseURL: false)
components?.queryItems = context.map { key, value in
Copy link
Contributor Author

Choose a reason for hiding this comment

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

safe URL manipulation instead of string concatenation. No matter what strings we put into context the URL is always correctly escaped

@kwasniew kwasniew changed the title Fix url formatting Fix url encoding May 15, 2023
@kwasniew kwasniew changed the title Fix url encoding Safe URL encoding May 15, 2023
Copy link
Contributor

@thomasheartman thomasheartman left a comment

Choose a reason for hiding this comment

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

This looks great! Very happy to see the use of URL instead of String where possible 🙌🏼 Does this change our public API? I would guess this requires a major version update before it can be released?

@kwasniew
Copy link
Contributor Author

kwasniew commented May 15, 2023

@thomasheartman Actually I deliberately left the public API of the Unleash client as string and we turn it into a URL in the very first step, failing otherwise. API of the poller changes but it's used internally.

@kwasniew kwasniew merged commit cb7c7f6 into main May 15, 2023
2 checks passed
@kwasniew kwasniew deleted the fix-url-formatting branch May 15, 2023 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

URL parameters are not encoded
2 participants