Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #23 from vapor/tn-add-reserved
Browse files Browse the repository at this point in the history
Encode reserved characters
  • Loading branch information
tanner0101 authored Feb 13, 2020
2 parents 82d8d63 + 02bd8ff commit 44999b4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/*.xcodeproj
Package.resolved
DerivedData
.swiftpm

2 changes: 1 addition & 1 deletion Sources/URLEncodedForm/Data/URLEncodedFormSerializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ private extension String {
/// Characters allowed in form-urlencoded data.
private var _allowedCharacters: CharacterSet = {
var allowed = CharacterSet.urlQueryAllowed
allowed.remove("+")
allowed.remove(charactersIn: "?&=[];+")
return allowed
}()
11 changes: 11 additions & 0 deletions Tests/URLEncodedFormTests/URLEncodedFormCodableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,24 @@ class URLEncodedFormCodableTests: XCTestCase {
XCTAssertEqual(foo.flag, true)
}

/// https://github.com/vapor/url-encoded-form/issues/3
func testEncodeReserved() throws {
struct Foo: Codable {
var reserved: String
}
let foo = Foo(reserved: "?&=[];+")
let data = try URLEncodedFormEncoder().encode(foo)
XCTAssertEqual(String(decoding: data, as: UTF8.self), "reserved=%3F%26%3D%5B%5D%3B%2B")
}

static let allTests = [
("testDecode", testDecode),
("testEncode", testEncode),
("testCodable", testCodable),
("testDecodeIntArray", testDecodeIntArray),
("testRawEnum", testRawEnum),
("testGH3", testGH3),
("testEncodeReserved", testEncodeReserved),
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class URLEncodedFormSerializerTests: XCTestCase {
func testPercentEncodingWithAmpersand() throws {
let form: [String: URLEncodedFormData] = ["aaa": "b%26&b"]
let data = try URLEncodedFormSerializer.default.serialize(form)
XCTAssertEqual(String(data: data, encoding: .utf8)!, "aaa=b%2526&b")
XCTAssertEqual(String(data: data, encoding: .utf8)!, "aaa=b%2526%26b")
}

func testNested() throws {
Expand Down
4 changes: 2 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
steps:
- run:
name: Clone Vapor
command: git clone -b master https://github.com/vapor/vapor.git
command: git clone -b 3 https://github.com/vapor/vapor.git
working_directory: ~/
- run:
name: Switch Vapor to this URLEncodedForm revision
Expand Down Expand Up @@ -62,4 +62,4 @@ workflows:
jobs:
- linux
# - macos


0 comments on commit 44999b4

Please sign in to comment.