Merge branch 'development' into swift3

* development:
  Don't parse twice for errors
  use guarded try
  change spm name
  Modify mac version base mac os 10.9
This commit is contained in:
Erik Little 2016-09-08 07:30:28 -04:00
commit a55e9ab3ba
No known key found for this signature in database
GPG Key ID: BC28525205A08B33
5 changed files with 21 additions and 14 deletions

View File

@ -1,5 +1,5 @@
import PackageDescription import PackageDescription
let package = Package( let package = Package(
name: "SocketIOClientSwift" name: "SocketIO"
) )

View File

@ -12,7 +12,7 @@ Pod::Spec.new do |s|
s.license = { :type => 'MIT' } s.license = { :type => 'MIT' }
s.author = { "Erik" => "nuclear.ace@gmail.com" } s.author = { "Erik" => "nuclear.ace@gmail.com" }
s.ios.deployment_target = '8.0' s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.10' s.osx.deployment_target = '10.9'
s.tvos.deployment_target = '9.0' s.tvos.deployment_target = '9.0'
s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v7.0.3' } s.source = { :git => "https://github.com/socketio/socket.io-client-swift.git", :tag => 'v7.0.3' }
s.source_files = "Source/**/*.swift" s.source_files = "Source/**/*.swift"

View File

@ -26,8 +26,9 @@ class SocketParserTest: XCTestCase {
"0/swift": ("/swift", [], [], -1), "0/swift": ("/swift", [], [], -1),
"1/swift": ("/swift", [], [], -1), "1/swift": ("/swift", [], [], -1),
"4\"ERROR\"": ("/", ["ERROR"], [], -1), "4\"ERROR\"": ("/", ["ERROR"], [], -1),
"4{\"test\":2}": ("/", [["test": 2] as NSDictionary], [], -1), "4{\"test\":2}": ("/", [["test": 2]], [], -1),
"41": ("/", [1], [], -1)] "41": ("/", [1], [], -1),
"4[1, \"hello\"]": ("/", [1, "hello"], [], -1)]
func testDisconnect() { func testDisconnect() {
let message = "1" let message = "1"
@ -99,6 +100,11 @@ class SocketParserTest: XCTestCase {
validateParseResult(message) validateParseResult(message)
} }
func testErrorTypeArray() {
let message = "4[1, \"hello\"]"
validateParseResult(message)
}
func testInvalidInput() { func testInvalidInput() {
let message = "8" let message = "8"
switch testSocket.parseString(message) { switch testSocket.parseString(message) {

View File

@ -358,6 +358,7 @@ public final class SocketEngine : NSObject, URLSessionDelegate, SocketEnginePoll
private func handleOpen(openData: String) { private func handleOpen(openData: String) {
guard let json = try? openData.toNSDictionary() else { guard let json = try? openData.toNSDictionary() else {
didError(reason: "Error parsing open packet") didError(reason: "Error parsing open packet")
return return
} }

View File

@ -107,17 +107,17 @@ extension SocketParsable {
} }
} }
let d = message[reader.advance(by: 1)..<message.endIndex]
switch parseData(d) {
case let .left(err): var dataArray = message[message.characters.index(reader.currentIndex, offsetBy: 1)..<message.endIndex]
// Errors aren't always enclosed in an array
if case let .right(data) = parseData("[\(d)]") { if type == .error && !dataArray.hasPrefix("[") && !dataArray.hasSuffix("]") {
return .right(SocketPacket(type: type, data: data, id: Int(idString) ?? -1, dataArray = "[" + dataArray + "]"
nsp: namespace, placeholders: placeholders))
} else {
return .left(err)
} }
switch parseData(dataArray) {
case let .left(err):
return .left(err)
case let .right(data): case let .right(data):
return .right(SocketPacket(type: type, data: data, id: Int(idString) ?? -1, return .right(SocketPacket(type: type, data: data, id: Int(idString) ?? -1,
nsp: namespace, placeholders: placeholders)) nsp: namespace, placeholders: placeholders))