Skip to content

Commit

Permalink
Merge pull request #681 from aterris/master
Browse files Browse the repository at this point in the history
Match pre-swift3 behavior for String -> Bool
  • Loading branch information
zhigang1992 committed Oct 21, 2016
2 parents 4cbe898 + a544199 commit 6a0c3a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Source/SwiftyJSON.swift
Expand Up @@ -711,7 +711,9 @@ extension JSON { // : Swift.Bool
case .number:
return self.rawNumber.boolValue
case .string:
return self.rawString.caseInsensitiveCompare("true") == .orderedSame
return ["true", "y", "t"].contains() { (truthyString) in
return self.rawString.caseInsensitiveCompare(truthyString) == .orderedSame
}
default:
return false
}
Expand Down
15 changes: 15 additions & 0 deletions Tests/StringTests.swift
Expand Up @@ -41,6 +41,21 @@ class StringTests: XCTestCase {
XCTAssertEqual(json.URL!, URL(string:"http://github.com")!)
}

func testBool() {
let json = JSON("true")
XCTAssertTrue(json.boolValue)
}

func testBoolWithY() {
let json = JSON("Y")
XCTAssertTrue(json.boolValue)
}

func testBoolWithT() {
let json = JSON("T")
XCTAssertTrue(json.boolValue)
}

func testURLPercentEscapes() {
let emDash = "\\u2014"
let urlString = "http://examble.com/unencoded" + emDash + "string"
Expand Down

0 comments on commit 6a0c3a8

Please sign in to comment.