https://kotlinlang.org logo
#ktor
Title
# ktor
a

Arnau Miro

03/17/2021, 4:37 PM
Hi guys, having troubles with call.parameter with "+" as a character. I have ContentNegotiation and DataConversion setted. Someone knows what can it be? Thanks.
m

Marc Knaup

03/17/2021, 4:46 PM
What is the trouble?
+
in a URL query parameter means a space character. If you wand to send a real
+
then you have to escape it.
a

Arnau Miro

03/17/2021, 4:47 PM
Yes you are right, I get an space. I need to get a "+"
m

Marc Knaup

03/17/2021, 4:48 PM
Then the problem is probably on the client side and the request URL is invalid.
a

Arnau Miro

03/17/2021, 5:01 PM
Yes, you are right, many thanks
In this case I have an email parameter and the email has a "+"
How could you handle it?
m

Marc Knaup

03/17/2021, 5:11 PM
If you put some data in a URL you have to escape the data first. How do you construct your URL? Do you use Ktor’s
Url
?
a

Arnau Miro

03/17/2021, 5:12 PM
The data is construct by the client
m

Marc Knaup

03/17/2021, 5:13 PM
How?
a

Arnau Miro

03/17/2021, 5:13 PM
path/?email={email}
m

Marc Knaup

03/17/2021, 5:14 PM
You, you have to escape
email
before putting it into that URL.
With Ktor you could use
email.encodeURLParameter()
No idea what client you use.
Or language.
In JS/TS it would be
encodeURIComponent(email)
a

Arnau Miro

03/17/2021, 5:17 PM
JS
Perfect, gonna try it
encodeURLParameter(true)
first param is spaceToPlus
works
👍 1
now the problems is that the
@
is also
%40
m

Marc Knaup

03/17/2021, 5:20 PM
Yeah that’s okay
Correct in a URL
c

CLOVIS

03/17/2021, 5:52 PM
In general, be very aware about emails. Emails are a very weird format: emails can have spaces, quotes, etc.
☝️ 1