SwiftWebSocket icon indicating copy to clipboard operation
SwiftWebSocket copied to clipboard

WebSocket.url getter isn't safe enough

Open PSTDev opened this issue 9 years ago • 0 comments

I think WebSocket's url getter isn't safe enough. It calls InnerWebSocket.url getter:

 var url : String {
        return request.url!.description
    }

where request.url in some circumstances can be nil which leads to crush. For example when you create WebSocket instance with convenience init without parameters:

    /// Create a WebSocket object with a deferred connection; the connection is not opened until the .open() method is called.
    public convenience override init(){
        var request = URLRequest(url: URL(string: "http://apple.com")!)
        request.url = nil
        self.init(request: request, subProtocols: [])
    }

and then try somewhere just to NSLog WebSocket's instance url before opening connection with real url.

IMHO, it would be better if url getter will check for request.url == nil and return empty String in this case instead of just crush.

PSTDev avatar Dec 02 '16 10:12 PSTDev