Skip to content

Commit b6b86d6

Browse files
committed
Prepend https to tracking urls if necessary
Fix whitespacing
1 parent e84c4f9 commit b6b86d6

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

WooCommerce/Classes/Extensions/String+Woo.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,16 @@ extension String {
1717
return " "
1818
}
1919
}
20+
21+
22+
/// String: URL manipulation
23+
///
24+
extension String {
25+
func addHTTPSSchemeIfNecessary() -> String {
26+
if self.hasPrefix("http://") || self.hasPrefix("https://") {
27+
return self
28+
}
29+
30+
return "https://\(self)"
31+
}
32+
}

WooCommerce/Classes/ViewRelated/Orders/OrderDetailsViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,8 @@ private extension OrderDetailsViewController {
660660
return
661661
}
662662

663-
guard let trackingURL = tracking.trackingURL, let url = URL(string: trackingURL) else {
663+
guard let trackingURL = tracking.trackingURL?.addHTTPSSchemeIfNecessary(),
664+
let url = URL(string: trackingURL) else {
664665
return
665666
}
666667

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@
292292
D816DDBC22265DA300903E59 /* OrderTrackingTableViewCellTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D816DDBB22265DA300903E59 /* OrderTrackingTableViewCellTests.swift */; };
293293
D83C129F22250BF0004CA04C /* OrderTrackingTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D83C129D22250BEF004CA04C /* OrderTrackingTableViewCell.xib */; };
294294
D83C12A022250BF0004CA04C /* OrderTrackingTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D83C129E22250BEF004CA04C /* OrderTrackingTableViewCell.swift */; };
295+
D85B833D2230DC9D002168F3 /* StringWooTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D85B833C2230DC9D002168F3 /* StringWooTests.swift */; };
295296
/* End PBXBuildFile section */
296297

297298
/* Begin PBXContainerItemProxy section */
@@ -630,6 +631,7 @@
630631
D816DDBB22265DA300903E59 /* OrderTrackingTableViewCellTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderTrackingTableViewCellTests.swift; sourceTree = "<group>"; };
631632
D83C129D22250BEF004CA04C /* OrderTrackingTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = OrderTrackingTableViewCell.xib; sourceTree = "<group>"; };
632633
D83C129E22250BEF004CA04C /* OrderTrackingTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrderTrackingTableViewCell.swift; sourceTree = "<group>"; };
634+
D85B833C2230DC9D002168F3 /* StringWooTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = StringWooTests.swift; path = WooCommerceTests/Extensions/StringWooTests.swift; sourceTree = SOURCE_ROOT; };
633635
/* End PBXFileReference section */
634636

635637
/* Begin PBXFrameworksBuildPhase section */
@@ -982,6 +984,7 @@
982984
B57C744F20F56ED300EEFC87 /* Extensions */ = {
983985
isa = PBXGroup;
984986
children = (
987+
D85B833C2230DC9D002168F3 /* StringWooTests.swift */,
985988
B5980A6621AC91AA00EBF596 /* BundleWooTests.swift */,
986989
B57C5C9821B80E7100FF82B2 /* DataWooTests.swift */,
987990
746FC23C2200A62B00C3096C /* DateWooTests.swift */,
@@ -1985,6 +1988,7 @@
19851988
B53A569721123D3B000776C9 /* ResultsControllerUIKitTests.swift in Sources */,
19861989
B57C5C9921B80E7100FF82B2 /* DictionaryWooTests.swift in Sources */,
19871990
D816DDBC22265DA300903E59 /* OrderTrackingTableViewCellTests.swift in Sources */,
1991+
D85B833D2230DC9D002168F3 /* StringWooTests.swift in Sources */,
19881992
);
19891993
runOnlyForDeploymentPostprocessing = 0;
19901994
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import XCTest
2+
@testable import WooCommerce
3+
4+
5+
/// UIURL+Woo: Unit Tests
6+
///
7+
import XCTest
8+
9+
final class StringWooTests: XCTestCase {
10+
func testURLsWithSchemeRemainUnchanged() {
11+
let url = "https://automattic.com"
12+
let sanitizedURL = url.addHTTPSSchemeIfNecessary()
13+
14+
XCTAssertEqual(url, sanitizedURL)
15+
}
16+
17+
func testSchemeIsAddedToURLsWithoutScheme() {
18+
let expectedResult = "https://automattic.com"
19+
let url = "automattic.com"
20+
let sanitizedURL = url.addHTTPSSchemeIfNecessary()
21+
22+
XCTAssertEqual(sanitizedURL, expectedResult)
23+
}
24+
}

0 commit comments

Comments
 (0)