Skip to content

Commit ce1957b

Browse files
authored
Merge pull request #704 from mindbox-cloud/feature/MOBILE-180
MOBILE-180: Trim `operationsDomain` config value before blank check
1 parent 14b73fc commit ce1957b

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

Mindbox/InAppMessages/Configuration/Services/OperationsDomainConfigPolicy.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ enum OperationsDomainConfigPolicy {
2727
}
2828

2929
static func action(for raw: String?, currentlyStored: String?) -> Action {
30-
guard let value = raw, !value.isEmpty else {
30+
let trimmed = raw?.trimmingCharacters(in: .whitespacesAndNewlines)
31+
guard let value = trimmed, !value.isEmpty else {
3132
return currentlyStored == nil ? .keep : .clear
3233
}
3334

MindboxTests/Network/OperationsURLRoutingTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,36 @@ struct OperationsURLRoutingTests {
278278
#expect(OperationsDomainConfigPolicy.action(for: "", currentlyStored: "https://old.ru") == .clear)
279279
}
280280

281+
@Test("Policy — clears on whitespace-only string when something is stored (Android parity)")
282+
func policyClearsOnWhitespaceWhenStored() {
283+
#expect(OperationsDomainConfigPolicy.action(for: " ", currentlyStored: "https://old.ru") == .clear)
284+
#expect(OperationsDomainConfigPolicy.action(for: "\t\n ", currentlyStored: "https://old.ru") == .clear)
285+
}
286+
281287
@Test("Policy — no-ops when nothing stored and nothing came")
282288
func policyKeepsOnNothingToChange() {
283289
#expect(OperationsDomainConfigPolicy.action(for: nil, currentlyStored: nil) == .keep)
284290
#expect(OperationsDomainConfigPolicy.action(for: "", currentlyStored: nil) == .keep)
291+
#expect(OperationsDomainConfigPolicy.action(for: " ", currentlyStored: nil) == .keep)
292+
}
293+
294+
@Test("Policy — trims surrounding whitespace before evaluating value")
295+
func policyTrimsSurroundingWhitespace() {
296+
// Trimmed value matches stored after canonicalization → no-op.
297+
#expect(
298+
OperationsDomainConfigPolicy.action(for: " anonymizer.client.ru ", currentlyStored: "https://anonymizer.client.ru")
299+
== .keep
300+
)
301+
// Trimmed value differs from stored → save canonical form.
302+
#expect(
303+
OperationsDomainConfigPolicy.action(for: " new.client.ru ", currentlyStored: "https://old.ru")
304+
== .save("https://new.client.ru")
305+
)
306+
// Trimmed value with nothing stored → save canonical form.
307+
#expect(
308+
OperationsDomainConfigPolicy.action(for: " valid.host.ru ", currentlyStored: nil)
309+
== .save("https://valid.host.ru")
310+
)
285311
}
286312

287313
@Test("Policy — rejects format-broken incoming value (previous kept intact)")

0 commit comments

Comments
 (0)