http_uri:decode equivalent in uri_string module

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

http_uri:decode equivalent in uri_string module

shunichi shinohara
Hi List,

I'm now trying OTP-23.0-rc1 and find http_uri module's several functions are now
marked deprecated. The decode fuction, which just decodes "%HexHex", is one of
them and the compiler suggests to use uri_string module.
https://github.com/erlang/otp/blob/OTP-23.0-rc1/lib/inets/src/http_lib/http_uri.erl#L68

Reading uri_string.erl but I could not find equivalent function in it...
Similar one is decode function but it's module private, and it has
utf8 validation.
It's easy to implement it in my app, but it may be better that OTP has
the altenative.

Thanks,
Shino
Reply | Threaded
Open this post in threaded view
|

Re: http_uri:decode equivalent in uri_string module

Loïc Hoguin-3
After using uri_string:normalize(URI, [return_map]) or equivalent, there
are very few %HexHex left to decode. For example, the path will only
have %2f left and it should be trivial to do the final decode after
you've split the path into a path segment. It's a similar situation for
the other fragments. The function string:replace/4 is probably enough
for these cases.

In a related PR https://github.com/erlang/otp/pull/2492 we have
discussed this and the result was to improve the documentation. I don't
know if it's done yet.

If you still need a general decode function, Cowlib's cow_uri and cow_qs
still have them. Other third party projects probably do as well.

Cheers,

On 02/03/2020 05:15, Shunichi Shinohara wrote:

> Hi List,
>
> I'm now trying OTP-23.0-rc1 and find http_uri module's several functions are now
> marked deprecated. The decode fuction, which just decodes "%HexHex", is one of
> them and the compiler suggests to use uri_string module.
> https://github.com/erlang/otp/blob/OTP-23.0-rc1/lib/inets/src/http_lib/http_uri.erl#L68
>
> Reading uri_string.erl but I could not find equivalent function in it...
> Similar one is decode function but it's module private, and it has
> utf8 validation.
> It's easy to implement it in my app, but it may be better that OTP has
> the altenative.
>
> Thanks,
> Shino
>

--
Loïc Hoguin
https://ninenines.eu
Reply | Threaded
Open this post in threaded view
|

Re: http_uri:decode equivalent in uri_string module

shunichi shinohara
Hi Loïc,

Thanks for the information!
I will live with another hex decode implementation ;)

Thanks,
Shino.

2020年3月2日(月) 17:13 Loïc Hoguin <[hidden email]>:

>
> After using uri_string:normalize(URI, [return_map]) or equivalent, there
> are very few %HexHex left to decode. For example, the path will only
> have %2f left and it should be trivial to do the final decode after
> you've split the path into a path segment. It's a similar situation for
> the other fragments. The function string:replace/4 is probably enough
> for these cases.
>
> In a related PR https://github.com/erlang/otp/pull/2492 we have
> discussed this and the result was to improve the documentation. I don't
> know if it's done yet.
>
> If you still need a general decode function, Cowlib's cow_uri and cow_qs
> still have them. Other third party projects probably do as well.
>
> Cheers,
>
> On 02/03/2020 05:15, Shunichi Shinohara wrote:
> > Hi List,
> >
> > I'm now trying OTP-23.0-rc1 and find http_uri module's several functions are now
> > marked deprecated. The decode fuction, which just decodes "%HexHex", is one of
> > them and the compiler suggests to use uri_string module.
> > https://github.com/erlang/otp/blob/OTP-23.0-rc1/lib/inets/src/http_lib/http_uri.erl#L68
> >
> > Reading uri_string.erl but I could not find equivalent function in it...
> > Similar one is decode function but it's module private, and it has
> > utf8 validation.
> > It's easy to implement it in my app, but it may be better that OTP has
> > the altenative.
> >
> > Thanks,
> > Shino
> >
>
> --
> Loïc Hoguin
> https://ninenines.eu