Skip to content

Commit

Permalink
Add parameter allowed encoding to error descriptions (#795)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1203790657351911/1207097497487052/f
iOS PR: duckduckgo/iOS#2781
macOS PR: duckduckgo/macos-browser#2691
What kind of version bump will this require?: Patch
  • Loading branch information
jaceklyp authored Apr 24, 2024
1 parent 89442d0 commit b1501e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Sources/Common/Extensions/URLExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ extension URL {

}

fileprivate extension CharacterSet {
public extension CharacterSet {

/**
* As per [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986#section-2.2).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,7 @@ public struct BrokenSiteReport {
}

if let errors {
let errorDescriptions: [String] = errors.map {
let error = $0 as NSError
return "\(error.code) - \(error.domain):\(error.localizedDescription)"
}
result["errorDescriptions"] = errorDescriptions.joined(separator: ",")
result["errorDescriptions"] = encodeErrors(errors)
}

if let jsPerformance {
Expand All @@ -256,4 +252,14 @@ public struct BrokenSiteReport {
return result
}

private func encodeErrors(_ errors: [Error]) -> String {
let errorDescriptions: [String] = errors.map {
let error = $0 as NSError
return "\(error.code) - \(error.domain):\(error.localizedDescription)"
}
let jsonString = try? String(data: JSONSerialization.data(withJSONObject: errorDescriptions), encoding: .utf8)!
let encodedString = jsonString?.addingPercentEncoding(withAllowedCharacters: .urlQueryParameterAllowed)
return encodedString ?? ""
}

}

0 comments on commit b1501e6

Please sign in to comment.