Skip to content
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

Fix crash when request download with fileURL #3318

Merged
merged 2 commits into from Oct 5, 2020
Merged

Conversation

devtak
Copy link
Contributor

@devtak devtak commented Oct 3, 2020

Issue Link πŸ”—

#3293

Goals ⚽

Crash occurs when request download with fileURL (AF.download)

  • modified to throw an error without causing a crash.

Implementation Details 🚧

If URL is fileURL, throw AFError.invalidURL

switch request {
    case is DownloadRequest:
        if let url = initialRequest.url, url.isFileURL {
            throw AFError.invalidURL(url: url)
        }
    default:
        break
}

Testing Details πŸ”

add downloadTestCase (testDownloadRequestWithLocalFileURLStringThrowsAnError)

@jshier
Copy link
Contributor

jshier commented Oct 3, 2020

Thanks for the PR. However, can you be more specific about the crash you're seeing? Additionally, if a file URL doesn't work for DownloadRequest, is it also broken for DataRequest and the others as well? If that's the case we probably want this logic in a more general location, like our URLRequest validation.

@jshier jshier self-assigned this Oct 3, 2020
@jshier
Copy link
Contributor

jshier commented Oct 3, 2020

Investigating this error more, this definitely seems like something that should just be general check in our validate() method on URLRequest. This lives in our Alamofire+URLRequest.swift file. You could add this to the top of the validate function:

if let url = url, url.isFileURL {
    // This should become another urlRequestValidationFailed error in Alamofire 6.
    throw AFError.invalidURL(url: url)
}

Additional tests for DataRequest and DataStreamRequest would also be needed.

@devtak
Copy link
Contributor Author

devtak commented Oct 4, 2020

@jshier i updated it. thanks for the review

Copy link
Contributor

@jshier jshier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘ Nice catch, thanks!

@jshier jshier merged commit 9e6f326 into Alamofire:master Oct 5, 2020
@jshier jshier added this to the 5.3.0 milestone Oct 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants