Skip to content

URL validation in RequestManager.processSNAURL only fails with an empty string #24

Description

@paynerc

I am currently implementing SNA in a project and have found that during testing that the SNA SDK will crash in the lower level network code if the snaURL string isn't a valid networking URL. The check that happens here:

guard let url = URL(string: url) else {
onComplete(.failure(.invalidUrl))
return
}

really only fails if the string is an empty string. Anything else and the URL is happily created. Later on down the line when it tries to get the host and such, it returns nil and that causes crashes deep in the network code.

To handle this in my current code, I am checking to see that the SNA url I am getting back is valid, and if it is not, I pass an empty string down to the SNA SDK so that it will fire the .invalidUrl error.

It would be helpful if the validation here included a few more items, such as:

guard
  let url = URL(string: url),
  let scheme = url.scheme?.lowercased(),
  scheme.hasPrefix("http"),
  url.host != nil = else { 
    onComplete(.failure(.invalidUrl)) 
    return 
} 

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions