浏览代码

Added the "[" and "]" to the legal escape characters and added more documentation.

Christian Noon 10 年之前
父节点
当前提交
12528b6ccb
共有 2 个文件被更改,包括 8 次插入1 次删除
  1. 5 1
      Source/ParameterEncoding.swift
  2. 3 0
      Tests/ParameterEncodingTests.swift

+ 5 - 1
Source/ParameterEncoding.swift

@@ -151,7 +151,11 @@ public enum ParameterEncoding {
     }
 
     func escape(string: String) -> String {
-        let legalURLCharactersToBeEscaped: CFStringRef = ":&=;+!@#$()',*"
+        let generalDelimiters = ":#[]@" // dropping "?" and "/" due to RFC 3986 - Section 3.4
+        let subDelimiters = "!$&'()*+,;="
+
+        let legalURLCharactersToBeEscaped: CFStringRef = generalDelimiters + subDelimiters
+
         return CFURLCreateStringByAddingPercentEscapes(nil, string, nil, legalURLCharactersToBeEscaped, CFStringBuiltInEncodings.UTF8.rawValue) as String
     }
 }

+ 3 - 0
Tests/ParameterEncodingTests.swift

@@ -30,6 +30,9 @@ class ParameterEncodingTestCase: BaseTestCase {
 
 // MARK: -
 
+/**
+    The URL parameter encoding tests cover a variety of cases for encoding query parameters in addition to percent escaping reserved characters. The percent escaping implementation follows RFC 3986 - Sections 2.2, 2.4 and 3.4. All reserved characters are percent encoded with the exception of the "?" and "/" characters. This exception was made to allow other URIs to be included as query parameters without issue. See RFC 3986 - Section 3.4 for more details.
+*/
 class URLParameterEncodingTestCase: ParameterEncodingTestCase {
     // MARK: Properties