#1 2023-07-28 09:46:36

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

Is there a urlEncode/urlDecode function that implements RFC3986

url encoding in RFC3986 is different from urlEncode in mormot.core.buffers. Spaces cannot be replaced with +

Offline

#2 2023-07-28 12:58:30

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,662
Website

Re: Is there a urlEncode/urlDecode function that implements RFC3986

You are right: current UrlEncode/UrlDecode are for URI parameters, in which spaces are converted into the plus sign.
But for the main URI itself, it won't work as expected by RFC 3986.

Please try and check the new UrlEncodeName/UrlDecodeName functions:
https://github.com/synopse/mORMot2/commit/60f30baa

Offline

#3 2023-07-29 01:59:33

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

Re: Is there a urlEncode/urlDecode function that implements RFC3986

Thanks for your quick response, but shouldn't the space2plus argument for calling _UrlEncode_ComputeLen in urlencodeName be 48('0')? Should it be 43('+').

Offline

#4 2023-07-29 02:26:43

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

Re: Is there a urlEncode/urlDecode function that implements RFC3986

In RFC3986, should '+'(43) be converted to %43?

Offline

#5 2023-07-29 04:07:31

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

Re: Is there a urlEncode/urlDecode function that implements RFC3986

RFC3986 rules will not encode ~, PHP rawUrlEncode from version 5.3 support RFC3986, the previous version will encode ~, Ali, Tencent api coding is to follow this rule.

Offline

#6 2023-07-29 07:14:54

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,662
Website

Re: Is there a urlEncode/urlDecode function that implements RFC3986

AFAIK '+'(43) should be converted to '%2B'.
As it is the case:
https://github.com/synopse/mORMot2/commit/4fa6b86a

About tilde ('~') this is a debate matter.
See https://blog.synopse.info/?post/2020/08 … -The-Tilde
and https://jkorpela.fi/tilde.html
The RFC should better not be followed in practice for this character.

Offline

#7 2023-07-29 07:29:53

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

Re: Is there a urlEncode/urlDecode function that implements RFC3986

or You can add an argument to the urlencode(urlEncodeName) function, and it is up to the user to decide whether ~ is encoded or not

Offline

#8 2023-07-29 07:35:14

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,662
Website

Re: Is there a urlEncode/urlDecode function that implements RFC3986

It will be decoded anyway on the other side, so it is safe to use.

Offline

#9 2023-07-29 07:44:01

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

Re: Is there a urlEncode/urlDecode function that implements RFC3986

api calls from ali,tencent, or other services will sign the encoded url. If the encoding results are inconsistent, the signature verification will fail

Offline

#10 2023-07-29 08:43:31

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,662
Website

Re: Is there a urlEncode/urlDecode function that implements RFC3986

Isn't the encoded URI what is transmitted, therefore signed?

Offline

#11 2023-07-29 09:03:26

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

Re: Is there a urlEncode/urlDecode function that implements RFC3986

The encoded URI is transmitted, but a signature field is added, and the signature field is based on this encoded URI. The result is definitely different if the string contains ~ and %7E

Offline

#12 2023-07-29 10:29:09

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,662
Website

Re: Is there a urlEncode/urlDecode function that implements RFC3986

Yes, but I guess that since it is the client which makes the encoding, the signature will take it into account, because everything is done on the client side.
The result is different but still properly signed, and could properly be decoded on the server side.
I can't see how it may fail.

Offline

#13 2023-07-29 14:09:59

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

Re: Is there a urlEncode/urlDecode function that implements RFC3986

Thank you. I'll test it later

Offline

#14 2023-10-19 09:41:34

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

Re: Is there a urlEncode/urlDecode function that implements RFC3986

I find using TDocVariantData sortByName, and toUrlEncode can satisfy many platform API calls, if the toUrlEncode can choose encoding rules: use urlEncode or urlencodeName, so much the better

Offline

Board footer

Powered by FluxBB