Skip to content

Commit 4b848f8

Browse files
committed
Ensure neither an empty nor a whitespace only string can trigger the interstitial page
1 parent 4f9f621 commit 4b848f8

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

Sources/App/Core/AppEnvironment.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ extension AppEnvironment {
195195
Environment.get("HIDE_STAGING_BANNER").flatMap(\.asBool)
196196
?? Constants.defaultHideStagingBanner
197197
},
198-
homepageInterstitial: { Environment.get("HOMEPAGE_INTERSTITIAL") },
198+
homepageInterstitial: {
199+
Environment.get("HOMEPAGE_INTERSTITIAL").flatMap(\.trimmed)
200+
},
199201
httpClient: { httpClient },
200202
loadSPIManifest: { path in SPIManifest.Manifest.load(in: path) },
201203
logger: { logger },

Sources/App/Core/Extensions/String+ext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension String {
4545
}
4646

4747
var trimmed: String? {
48-
let trimmedString = trimmingCharacters(in: .whitespaces)
48+
let trimmedString = trimmingCharacters(in: .whitespacesAndNewlines)
4949
if trimmedString.isEmpty { return nil }
5050
return trimmedString
5151
}

Tests/AppTests/AppEnvironmentTests.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,29 @@ class AppEnvironmentTests: XCTestCase {
2929
XCTAssertEqual(Current.fileManager.checkoutsDirectory(), "/tmp/foo")
3030
}
3131

32+
func test_homepageInterstitial() throws {
33+
defer { unsetenv("HOMEPAGE_INTERSTITIAL") }
34+
Current.homepageInterstitial = AppEnvironment.live.homepageInterstitial
35+
do {
36+
unsetenv("HOMEPAGE_INTERSTITIAL")
37+
XCTAssertEqual(Current.homepageInterstitial(), nil)
38+
}
39+
do {
40+
setenv("HOMEPAGE_INTERSTITIAL", "foo", 1)
41+
XCTAssertEqual(Current.homepageInterstitial(), "foo")
42+
}
43+
do {
44+
setenv("HOMEPAGE_INTERSTITIAL", "", 1)
45+
XCTAssertEqual(Current.homepageInterstitial(), nil)
46+
}
47+
do {
48+
setenv("HOMEPAGE_INTERSTITIAL", " ", 1)
49+
XCTAssertEqual(Current.homepageInterstitial(), nil)
50+
}
51+
do {
52+
setenv("HOMEPAGE_INTERSTITIAL", " \t\n ", 1)
53+
XCTAssertEqual(Current.homepageInterstitial(), nil)
54+
}
55+
}
56+
3257
}

0 commit comments

Comments
 (0)