Skip to content

[iOS] - Fix download filename. Fix download host. (uplift to 1.78.x) #28727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ extension BrowserViewController: TabDownloadDelegate {
suggestedFileName: String
) async -> Bool {
// Only download if there is a valid host
guard let host = download.originalURL?.host() else {
return false
}
let host = download.originalURL?.host() ?? ""

// Never present the download alert on a tab that isn't visible
guard tab === tabManager.selectedTab
Expand All @@ -200,7 +198,7 @@ extension BrowserViewController: TabDownloadDelegate {
? ByteCountFormatter.string(fromByteCount: totalBytesExpected!, countStyle: .file)
: nil

let title = "\(filename) - \(host)"
let title = host.isEmpty ? "\(filename)" : "\(filename) - \(host)"

var downloadActionText = Strings.download
if let expectedSize = expectedSize {
Expand Down
9 changes: 8 additions & 1 deletion ios/brave-ios/Sources/Web/Download.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ open class Download: NSObject {
originalURL: URL?,
mimeType: String? = nil
) {
self.filename = suggestedFilename

// Strip out Unicode Bidi Control characters for RLO — Right-to-Left Override & LRO overrides
self.filename = String(
suggestedFilename.unicodeScalars.filter {
!$0.properties.isBidiControl
}.map(Character.init)
)

self.originalURL = originalURL
self.mimeType = mimeType ?? "application/octet-stream"

Expand Down
2 changes: 0 additions & 2 deletions ios/brave-ios/Sources/Web/WebKit/WebKitDownload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class WebKitDownload: Download {
mimeType: response.mimeType
)

self.originalURL = download.originalRequest?.url

self.totalBytesExpected =
response.expectedContentLength > 0 ? response.expectedContentLength : nil

Expand Down
5 changes: 5 additions & 0 deletions ios/brave-ios/Tests/ClientTests/DownloadQueueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ class DownloadQueueTests: XCTestCase {
]
)
}

func test_downloadSuggestedFileName_UnicodeBidiControlEscaped() {
let download = Download(suggestedFilename: "file\u{0000202e}4pm.doc", originalURL: nil)
XCTAssertEqual(download.filename, "file4pm.doc")
}
}

// MARK: - Tests Helpers
Expand Down
Loading