Skip to content

[SR-9887] HTTPCookie on Linux does not accept Substring values #2022

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

Merged
merged 1 commit into from
Mar 25, 2019

Conversation

saiHemak
Copy link
Contributor

The HTTPCookie initializer takes values as Any but fails to create cookie when Substring is passed to it. Casting from Substring to String returns nil due to which the initializer is failing silently.

@spevans
Copy link
Contributor

spevans commented Mar 19, 2019

@swift-ci test

if let str = strVal as? String {
return str
} else if let subStr = strVal as? Substring {
return String(_: subStr)
Copy link
Member

Choose a reason for hiding this comment

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

This could just be String(subStr)

@@ -377,6 +377,15 @@ open class HTTPCookie : NSObject {
}
}

private class func getStringValue(strVal: Any?) -> String? {
Copy link
Member

Choose a reason for hiding this comment

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

Three suggestions here:

  1. Though this function name serves the purpose, we could shorten it, may be something like stringValue. Just a suggestion :)
  2. Could this function be nested inside the initialiser where it is being used?
  3. Because we only seem to be adding support for Substrings, do we really need the strVal as? String check?

@saiHemak saiHemak force-pushed the http-cookie branch 3 times, most recently from dc54a7a to 24070d6 Compare March 20, 2019 06:40
@spevans
Copy link
Contributor

spevans commented Mar 20, 2019

@swift-ci test

1 similar comment
@pushkarnk
Copy link
Member

@swift-ci test

@@ -377,6 +377,15 @@ open class HTTPCookie : NSObject {
}
}

private class func getStringValue(strVal: Any?) -> String? {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the method signature would read better if it is updated something like this getStringValue(_ strValue: Any?)

Copy link
Contributor

Choose a reason for hiding this comment

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

the words StringValue in the method name and the strVal parameter label reads redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done ..thanks

@spevans
Copy link
Contributor

spevans commented Mar 25, 2019

@swift-ci test

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.

5 participants