Skip to content

Commit

Permalink
Support Autofill Domains with Port Number Suffixes (#2602)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1199230911884351/1206023722645078/f

**Description**:
This PR includes the following changes:
* BSK 134.1.0
* Adds a `URLExtension` method which fixes an new issue where the
Autofill dialog didn’t open with the right account highlighted, when the
domain had a port suffix
* Adds tests for above
  • Loading branch information
aataraxiaa authored Apr 15, 2024
1 parent 1695f18 commit ef05acd
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14544,7 +14544,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 134.0.1;
version = 134.1.0;
};
};
9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "b0749d25996c0fa18be07b7851f02ebb3b9fab50",
"version" : "134.0.1"
"revision" : "90e789b95403481e7c2f0e4aa661890d4252f0e6",
"version" : "134.1.0"
}
},
{
Expand Down
8 changes: 8 additions & 0 deletions DuckDuckGo/Common/Extensions/URLExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ extension URL {
return string
}

func hostAndPort() -> String? {
guard let host else { return nil }

guard let port = port else { return host }

return "\(host):\(port)"
}

#if !SANDBOX_TEST_TOOL
func toString(forUserInput input: String, decodePunycode: Bool = true) -> String {
let hasInputScheme = input.hasOrIsPrefix(of: self.separatedScheme ?? "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,10 +710,11 @@ final class NavigationBarViewController: NSViewController {
}

popovers.passwordManagementDomain = nil
guard let url = url, let domain = url.host else {
guard let url = url, let hostAndPort = url.hostAndPort() else {
return
}
popovers.passwordManagementDomain = domain

popovers.passwordManagementDomain = hostAndPort
}

private func updateHomeButton() {
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/DataBrokerProtection/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let package = Package(
targets: ["DataBrokerProtection"])
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "134.0.1"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "134.1.0"),
.package(path: "../PixelKit"),
.package(path: "../SwiftUIExtensions"),
.package(path: "../XPCHelper"),
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/NetworkProtectionMac/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let package = Package(
.library(name: "NetworkProtectionUI", targets: ["NetworkProtectionUI"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "134.0.1"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "134.1.0"),
.package(path: "../XPCHelper"),
.package(path: "../SwiftUIExtensions"),
.package(path: "../LoginItems"),
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/SubscriptionUI/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
targets: ["SubscriptionUI"]),
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "134.0.1"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "134.1.0"),
.package(path: "../SwiftUIExtensions")
],
targets: [
Expand Down
24 changes: 24 additions & 0 deletions UnitTests/Common/Extensions/URLExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,28 @@ final class URLExtensionTests: XCTestCase {
}
}

func testWhenGetHostAndPort_WithPort_ThenHostAndPortIsReturned() throws {
// Given
let expected = "duckduckgo.com:1234"
let sut = URL(string: "https://duckduckgo.com:1234")

// When
let result = sut?.hostAndPort()

// Then
XCTAssertEqual(expected, result)
}

func testWhenGetHostAndPort_WithoutPort_ThenHostReturned() throws {
// Given
let expected = "duckduckgo.com"
let sut = URL(string: "https://duckduckgo.com")

// When
let result = sut?.hostAndPort()

// Then
XCTAssertEqual(expected, result)
}

}

0 comments on commit ef05acd

Please sign in to comment.