Skip to content

Commit 1c33f0d

Browse files
refactor: improve URL formatting and validation logic in CmabClient and CmabConfig
1 parent 23c23d5 commit 1c33f0d

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

Sources/CMAB/CmabClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class DefaultCmabClient: CmabClient {
101101
}
102102

103103
func getUrl(ruleId: String) -> URL? {
104-
let urlString = "\(predictionEndpoint)/\(ruleId)"
104+
let urlString = predictionEndpoint.hasSuffix("/") ? "predictionEndpoint\(ruleId)" : "\(predictionEndpoint)/\(ruleId)"
105105
guard let url = URL(string: urlString) else {
106106
self.logger.e("Invalid CMAB endpoint")
107107
return nil

Sources/CMAB/CmabConfig.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ public struct CmabConfig {
4040
self.cacheSize = cacheSize
4141
self.cacheTimeoutInSecs = cacheTimeoutInSecs
4242
// Sanitize and validate endpoint
43-
if let endpoint = predictionEndpoint?.trimmingCharacters(in: .whitespaces), !endpoint.isEmpty {
44-
// Remove trailing slashes
45-
var sanitized = endpoint
46-
if sanitized.hasSuffix("/") {
47-
sanitized = String(sanitized.dropLast())
48-
}
43+
if let sanitized = predictionEndpoint?.trimmingCharacters(in: .whitespaces), !sanitized.isEmpty {
4944
self.predictionEndpoint = sanitized
5045
} else {
5146
self.predictionEndpoint = CMAB_PREDICTION_END_POINT

0 commit comments

Comments
 (0)