Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protocol EndPoint {
var method: HTTPMethod { get }
var headers: HeaderType { get }
var parameterEncoding: ParameterEncoding { get }
var queryParameters: [String: String]? { get }
var queryParameters: [String: Any]? { get }
var bodyParameters: Parameters? { get }

var requestURL: URL { get }
Expand All @@ -45,7 +45,10 @@ extension EndPoint {

if let queryParameters {
urlComponents.queryItems = queryParameters.map {
URLQueryItem(name: $0, value: $1)
URLQueryItem(
name: $0.key,
value: String(describing: $0.value)
)
Comment on lines +48 to +51
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

String(describing:)의 Optional 처리 동작에 주의하세요

String(describing:)은 Optional 값을 전달받으면 "Optional(123)" 또는 "nil" 형태의 문자열을 생성합니다. 이로 인해 예상치 못한 쿼리 스트링이 서버로 전송될 수 있습니다.

예시:

let value: Int? = 123
String(describing: value) // "Optional(123)" ❌
"\(value!)"               // "123" ✅ (단, 강제 언래핑 필요)
🛠️ Optional 안전 처리를 위한 수정 제안
         if let queryParameters {
-            urlComponents.queryItems = queryParameters.map {
-                URLQueryItem(
-                    name: $0.key,
-                    value: String(describing: $0.value)
-                )
-            }
+            urlComponents.queryItems = queryParameters.compactMap { key, value in
+                if case Optional<Any>.none = value {
+                    return nil
+                }
+                let stringValue: String
+                if let optional = value as? any OptionalProtocol {
+                    stringValue = optional.wrappedDescription
+                } else {
+                    stringValue = "\(value)"
+                }
+                return URLQueryItem(name: key, value: stringValue)
+            }
         }

또는 더 간단하게 "\($0.value)"를 사용하되, 호출하는 쪽에서 Optional이 아닌 값만 전달하도록 문서화하는 방법도 있습니다:

-                    value: String(describing: $0.value)
+                    value: "\($0.value)"
🤖 Prompt for AI Agents
In `@Cherrish-iOS/Cherrish-iOS/Data/Network/EndPoint/EndPoint.swift` around lines
48 - 51, EndPoint에서 URLQueryItem을 만들 때 String(describing: $0.value)로 Optional을
그대로 문자열화하면 "Optional(...)" 또는 "nil"이 전송되니, Optional을 안전하게 처리하도록 변경하세요: 파라미터
딕셔너리에서 nil 값을 필터링(compactMap)하거나 각 값에 대해 value.map { String($0) } 또는
"\(unwrapped)" 방식으로 언래핑한 문자열을 사용해 URLQueryItem(name: $0.key, value:
unwrappedString)으로 생성하도록 수정을 적용(참조심볼: URLQueryItem, $0.key, $0.value,
EndPoint.swift).

}
}

Expand Down