Skip to content

Commit

Permalink
Merge pull request #43 from niscy-eudiw/bugfix/credential-offer-url-l…
Browse files Browse the repository at this point in the history
…egacy-os-fix

[fix] url parsing fix
  • Loading branch information
dtsiflit authored Jun 19, 2024
2 parents 613f2ab + c02a34d commit caf034c
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Sources/Entities/CredentialOffer/CredentialOfferRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ public enum CredentialOfferRequest {

public extension CredentialOfferRequest {
init(urlString: String) throws {

guard let url = URL(string: urlString) else {
throw CredentialOfferRequestError.nonParsableCredentialOfferEndpointUrl(reason: urlString)
}


let url = try Self.parseUrl(urlString)

let parameters = url.queryParameters
if let byValue = parameters["credential_offer"],
!byValue.isEmpty {
Expand All @@ -45,3 +43,17 @@ public extension CredentialOfferRequest {
}
}
}

private extension CredentialOfferRequest {
static func parseUrl(_ string: String) throws -> URL {
if let url = URL(string: string) {
return url

} else if let encodedString = string.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), let url = URL(string: encodedString) {
return url

} else {
throw CredentialOfferRequestError.nonParsableCredentialOfferEndpointUrl(reason: string)
}
}
}

0 comments on commit caf034c

Please sign in to comment.