tide icon indicating copy to clipboard operation
tide copied to clipboard

`cx.param` into a string doesn't handle url-decoding

Open nikomatsakis opened this issue 5 years ago • 5 comments

When using cx.param to extract strings, I expected it to handle URL decoding for me. However, it did not. I would up writing some fairly complex code to deal with this. In general, I would expect this to be the default, with some way to request the "raw string" if I really wanted to get that, but at least there should be some super ergonomic way to "url-decode" your request parameters.

Question

Is this by design? Am I overlooking a simple way to do url-decoding?

Additional context

This is part of a flashcard app. The incoming request parameters are sometimes in other languages, so they are url-encoded utf-8.

nikomatsakis avatar Jun 20 '19 01:06 nikomatsakis

Notes from triage: we should probably introduce a new API using https://docs.rs/serde_qs/0.5.0/serde_qs/ for this:

let params: MyType = cx.query();

Similar to how our current cx.body_json method currently works.

yoshuawuyts avatar Jul 25 '19 16:07 yoshuawuyts

When I wrote the Context extension, serde_qs had outstanding bugs that were unresolved for longer than preferred. It looks like those have now been cleared up.

I wonder if we can resolve at least a portion of this issue by updating to that library.

secretfader avatar Aug 03 '19 01:08 secretfader

serde_qs would be neat for query(), but it would not work for param() as they have different encoding rules. Importantly, + should be decoded to space in query(), but should be left alone for param().

kyrias avatar May 19 '20 11:05 kyrias

Uh what, how did me commenting that unassign him?

kyrias avatar May 19 '20 11:05 kyrias

Is there a recommendation in the mean time for how to easily percent-decode parameters when fetching from Tide?

emmiegit avatar Apr 09 '23 04:04 emmiegit