From d620e27eea7974b74117f77e556d0bf0062c842d Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Tue, 19 Dec 2023 16:01:18 -0700 Subject: add fallback for incorrectly formatted gophermaps --- .../gopherRequestResponseHandler.swift | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'Sources/swiftGopherClient') diff --git a/Sources/swiftGopherClient/gopherRequestResponseHandler.swift b/Sources/swiftGopherClient/gopherRequestResponseHandler.swift index 6cede51..8349c6e 100644 --- a/Sources/swiftGopherClient/gopherRequestResponseHandler.swift +++ b/Sources/swiftGopherClient/gopherRequestResponseHandler.swift @@ -88,12 +88,22 @@ final class GopherRequestResponseHandler: ChannelInboundHandler { "Carriage Returns: \(carriageReturnCount), Newline + Carriage Returns: \(newlineCarriageReturnCount)" ) - for line in response.split(separator: "\r\n") { - let lineItemType = getGopherFileType(item: "\(line.first ?? " ")") - let item = createGopherItem( - rawLine: String(line), itemType: lineItemType, rawData: originalBytes) - gopherServerResponse.append(item) + if carriageReturnCount == 0 { + for line in response.split(separator: "\n") { + let lineItemType = getGopherFileType(item: "\(line.first ?? " ")") + let item = createGopherItem( + rawLine: String(line), itemType: lineItemType, rawData: originalBytes) + gopherServerResponse.append(item) + } + } else { + for line in response.split(separator: "\r\n") { + let lineItemType = getGopherFileType(item: "\(line.first ?? " ")") + let item = createGopherItem( + rawLine: String(line), itemType: lineItemType, rawData: originalBytes) + gopherServerResponse.append(item) + + } } print("done parsing") -- cgit v1.2.3