-
-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error while query users with emails that contains +(plus) character #453
Labels
type:bug
Impaired feature or lacking behavior that is likely assumed
Comments
Thanks for opening this issue!
|
mtrezza
added
the
type:bug
Impaired feature or lacking behavior that is likely assumed
label
Dec 11, 2024
as workaround for someone ... func getUserWithEmail(_ email: String) async throws -> ParseUserObject? {
// Configure query json value
let whereQuery: [String: Any] = ["email": email]
let queryJSONData = try JSONSerialization.data(withJSONObject: whereQuery, options: [])
guard let jsonString = String(data: queryJSONData, encoding: .utf8) else { throw URLError(.badURL) }
// Configure url and encode "+" character manualy
var urlComponents = URLComponents()
urlComponents.scheme = "https"
urlComponents.host = "parseapi.back4app.com"
urlComponents.path = "/users"
urlComponents.queryItems = [.init(name: "where", value: jsonString)]
urlComponents.percentEncodedQuery = urlComponents.percentEncodedQuery?
.replacingOccurrences(of: "+", with: "%2B")
guard let url = urlComponents.url else { throw URLError(.badURL) }
// Performing request
var request = URLRequest(url: url)
request.httpMethod = "GET"
guard let appID = Bundle.main.object(forInfoDictionaryKey: "ParseAppID") as? String,
let restApiKey = Bundle.main.object(forInfoDictionaryKey: "ParseRestApiKey") as? String
else {
fatalError("Cannot find Parse SDK credentials")
}
request.addValue(appID, forHTTPHeaderField: "X-Parse-Application-Id")
request.addValue(restApiKey, forHTTPHeaderField: "X-Parse-REST-API-Key")
let (data, response) = try await URLSession.shared.data(for: request)
guard let httpResponse = response as? HTTPURLResponse,
(200...299).contains(httpResponse.statusCode)
else {
throw URLError(.badServerResponse)
}
let resposeArray = try JSONDecoder().decode(ParseResponse<ParseUserObject>.self, from: data)
guard let parseUser = resposeArray.results.first else { throw ParseError.Code.userWithEmailNotFound}
return parseUser
}
struct ParseResponse<T>: Codable where T: Codable {
let results: [T]
}
struct ParseUserObject: ParseUser {
enum CodingKeys: String, CodingKey {
case username, email, emailVerified, password, authData, originalData
case objectId, createdAt, updatedAt, ACL, displayName
}
var username: String?
var email: String?
var emailVerified: Bool?
var password: String?
var authData: [String : [String : String]?]?
var originalData: Data?
var objectId: String?
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var displayName: String?
init() {}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.username = try container.decodeIfPresent(String.self, forKey: .username)
self.email = try container.decodeIfPresent(String.self, forKey: .email)
self.emailVerified = try container.decodeIfPresent(Bool.self, forKey: .emailVerified)
self.password = try container.decodeIfPresent(String.self, forKey: .password)
self.authData = try container.decodeIfPresent([String: [String: String]?].self, forKey: .authData)
self.originalData = try container.decodeIfPresent(Data.self, forKey: .originalData)
self.objectId = try container.decodeIfPresent(String.self, forKey: .objectId)
self.ACL = try container.decodeIfPresent(ParseACL.self, forKey: .ACL)
self.displayName = try container.decodeIfPresent(String.self, forKey: .displayName)
self.createdAt = try? container.decodeIfPresent(Date.self, forKey: .createdAt)
self.updatedAt = try? container.decodeIfPresent(Date.self, forKey: .updatedAt)
}
}
extension ParseUserObject {
init(email: String, password: String) {
self.email = email
self.password = password
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
New Issue Checklist
Issue Description
When I try to query object from my database (based on back4app) with email that contains +(plus) characters I got Parse Error "Object not found".
If I try to query objects with email that contains other special characters- "_" or "." everything working ok.
Steps to reproduce
Actual Outcome
try await query.first() throw an Parse Error (object not found)
Expected Outcome
Existing object
Environment
Xcode, iOS simulator (or physical iPhone), parse database based on back4app service
Client
4.14.2
15.4
iOS
18.0
Server
3.10.0
Linux(maybe)
back4app server
Database
MongoDB
3.6
back4app server
Logs
▿ ParseError code=101 error=Object not found on the server.
The text was updated successfully, but these errors were encountered: