Преглед на файлове

Fixed content type validation issue where parameter parsing was incorrect.

Christian Noon преди 10 години
родител
ревизия
63fce12f7a
променени са 2 файла, в които са добавени 3 реда и са изтрити 1 реда
  1. 1 1
      Source/Validation.swift
  2. 2 0
      Tests/ValidationTests.swift

+ 1 - 1
Source/Validation.swift

@@ -94,7 +94,7 @@ extension Request {
         init?(_ string: String) {
             let components: [String] = {
                 let stripped = string.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
-                let split = stripped.substringToIndex(stripped.rangeOfString(";")?.endIndex ?? stripped.endIndex)
+                let split = stripped.substringToIndex(stripped.rangeOfString(";")?.startIndex ?? stripped.endIndex)
                 return split.componentsSeparatedByString("/")
             }()
 

+ 2 - 0
Tests/ValidationTests.swift

@@ -116,6 +116,8 @@ class ContentTypeValidationTestCase: BaseTestCase {
         // When
         Alamofire.request(.GET, URLString)
             .validate(contentType: ["application/json"])
+            .validate(contentType: ["application/json;charset=utf8"])
+            .validate(contentType: ["application/json;q=0.8;charset=utf8"])
             .response { _, _, _, responseError in
                 error = responseError
                 expectation.fulfill()