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

#964 solution #965

Open
wants to merge 1 commit into
base: feature/initJsonString
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions Source/SwiftyJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -977,11 +977,15 @@ extension JSON {
// Check for existing percent escapes first to prevent double-escaping of % character
if let _ = self.rawString.range(of: "%[0-9A-Fa-f]{2}", options: .regularExpression, range: nil, locale: nil) {
return Foundation.URL(string: self.rawString)
} else if let encodedString_ = self.rawString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) {
// We have to use `Foundation.URL` otherwise it conflicts with the variable name.
return Foundation.URL(string: encodedString_)
} else {
return nil
}else {

Choose a reason for hiding this comment

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

Statement Position Violation: Else and catch should be on the same line, one space after the previous declaration. (statement_position)

var charSet = CharacterSet.urlQueryAllowed
charSet.insert(charactersIn: "#")
if let encodedString_ = self.rawString.addingPercentEncoding(withAllowedCharacters: charSet) {
// We have to use `Foundation.URL` otherwise it conflicts with the variable name.
return Foundation.URL(string: encodedString_)
} else {
return nil
}
}
default:
return nil
Expand Down
3 changes: 3 additions & 0 deletions Tests/SwiftyJSONTests/StringTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class StringTests: XCTestCase {
func testURL() {
let json = JSON("http://github.com")
XCTAssertEqual(json.URL!, URL(string:"http://github.com")!)

Choose a reason for hiding this comment

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

Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)

let json2 = JSON("http://github.com#location")
XCTAssertEqual(json2.url!, URL(string: "http://github.com#location"))
}

func testBool() {
Expand Down