How should I decode escaped URL by unity in Swift?
I am developing a game with Unity3d. Something MMORPG. With server implemented by me in Swift
under Kitura framework
A framework doesn't matter that much. It is more about swift and Unity itself.
Let me describe the problem here.
Unity
UnityWebRequest.EscapeURL("First Last")
Escapes string with encoding used in the application/x-www-form-urlencoded
content-type: https://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
Which produce string First+Last
where +
maps to " "
space.
Swift:
import Foundation
var str = "First+Last"
print(str)
print(str.removingPercentEncoding)
The character used on this string +
isn't considered as a percentage encoding in the standard used by swift
. It would be if the character escaped as this would be represented by %20
.
So my server and client ended up with different string values. Later on returned from one to the other weren't equal. Which ended up considering them as two different clients.