|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Hummingbird server framework project |
| 4 | +// |
| 5 | +// Copyright (c) 2021-2024 the Hummingbird authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
1 | 15 | /// Internal representation of URL encoded form data used by both encode and decode
|
2 | 16 | enum URLEncodedFormNode: CustomStringConvertible, Equatable {
|
3 | 17 | /// holds a value
|
@@ -30,7 +44,7 @@ enum URLEncodedFormNode: CustomStringConvertible, Equatable {
|
30 | 44 | let node = Self.map(.init())
|
31 | 45 | for element in split {
|
32 | 46 | if let equals = element.firstIndex(of: "=") {
|
33 |
| - let before = element[..<equals].removingPercentEncoding |
| 47 | + let before = element[..<equals].removingURLPercentEncoding() |
34 | 48 | let afterEquals = element.index(after: equals)
|
35 | 49 | let after = element[afterEquals...].replacingOccurrences(of: "+", with: " ")
|
36 | 50 | guard let key = before else { throw Error.failedToDecode("Failed to percent decode \(element)") }
|
@@ -128,12 +142,12 @@ enum URLEncodedFormNode: CustomStringConvertible, Equatable {
|
128 | 142 | }
|
129 | 143 |
|
130 | 144 | init?(percentEncoded value: String) {
|
131 |
| - guard let value = value.removingPercentEncoding else { return nil } |
| 145 | + guard let value = value.removingURLPercentEncoding() else { return nil } |
132 | 146 | self.value = value
|
133 | 147 | }
|
134 | 148 |
|
135 | 149 | var percentEncoded: String {
|
136 |
| - self.value.addingPercentEncoding(withAllowedCharacters: URLEncodedForm.unreservedCharacters) ?? self.value |
| 150 | + self.value.addingPercentEncoding(forURLComponent: .queryItem) |
137 | 151 | }
|
138 | 152 |
|
139 | 153 | static func == (lhs: URLEncodedFormNode.NodeValue, rhs: URLEncodedFormNode.NodeValue) -> Bool {
|
|
0 commit comments