diff --git a/Sources/EeveeSpotify/Lyrics/Repositories/GeniusLyricsRepository.swift b/Sources/EeveeSpotify/Lyrics/Repositories/GeniusLyricsRepository.swift index 85f83a5..deb66b9 100644 --- a/Sources/EeveeSpotify/Lyrics/Repositories/GeniusLyricsRepository.swift +++ b/Sources/EeveeSpotify/Lyrics/Repositories/GeniusLyricsRepository.swift @@ -26,9 +26,7 @@ struct GeniusLyricsRepository: LyricsRepository { var stringUrl = "\(apiUrl)\(path)" if !query.isEmpty { - let queryString = query.queryString.addingPercentEncoding( - withAllowedCharacters: .urlHostAllowed - )! + let queryString = query.queryString stringUrl += "?\(queryString)" } diff --git a/Sources/EeveeSpotify/Lyrics/Repositories/LrclibLyricsRepository.swift b/Sources/EeveeSpotify/Lyrics/Repositories/LrclibLyricsRepository.swift index 2b9d4f5..c7736cf 100644 --- a/Sources/EeveeSpotify/Lyrics/Repositories/LrclibLyricsRepository.swift +++ b/Sources/EeveeSpotify/Lyrics/Repositories/LrclibLyricsRepository.swift @@ -20,9 +20,7 @@ struct LrcLibLyricsRepository: LyricsRepository { var stringUrl = "\(apiUrl)\(path)" if !query.isEmpty { - let queryString = query.queryString.addingPercentEncoding( - withAllowedCharacters: .urlHostAllowed - )! + let queryString = query.queryString stringUrl += "?\(queryString)" } diff --git a/Sources/EeveeSpotify/Models/Extensions/CharacterSet+Extension.swift b/Sources/EeveeSpotify/Models/Extensions/CharacterSet+Extension.swift new file mode 100644 index 0000000..ed1f78d --- /dev/null +++ b/Sources/EeveeSpotify/Models/Extensions/CharacterSet+Extension.swift @@ -0,0 +1,9 @@ +import Foundation + +extension CharacterSet { + static var urlQueryAllowedStrict: CharacterSet { + var allowed = CharacterSet.urlQueryAllowed + allowed.remove(charactersIn: "/?@&=+$") + return allowed + } +} \ No newline at end of file diff --git a/Sources/EeveeSpotify/Models/Extensions/Dictionary+Extension.swift b/Sources/EeveeSpotify/Models/Extensions/Dictionary+Extension.swift index b866c2f..a604f99 100644 --- a/Sources/EeveeSpotify/Models/Extensions/Dictionary+Extension.swift +++ b/Sources/EeveeSpotify/Models/Extensions/Dictionary+Extension.swift @@ -3,9 +3,13 @@ import Foundation extension Dictionary { var queryString: String { return self - .compactMap({ (key, value) -> String in - return "\(key)=\(value)" + .compactMap({ (key, value) -> String? in + guard let keyString = "\(key)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowedStrict), + let valueString = "\(value)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowedStrict) else { + return nil + } + return "\(keyString)=\(valueString)" }) - .joined(separator: "&") + .joined(separator: "&") } } \ No newline at end of file