Open borkdude opened 5 years ago
Good candidate for optimization:
I would leave parens unescaped, as they are valid url chars and most browsers don't proactively escape them. Most problematic characters will probably be space, brackets, colon. Using ~
as a macro character is fine though.
@wagjo Parens are an edge case. Twitter doesn’t deal with links that have a query parameter that ends with a paren well, it chops it off. Normally encodeURIComponent doesn’t encode it, I do it myself on top of that. This is the only exception so far.
It might be nice to have a general library which can encode clojure expressions as pretty url query params. E.g. we could encode parens as
~l
and~r
, brackets as~L
and~R
, + as~p
, etc. For(+ 1 2 [3 4 5])
this would yield:~l~p~_1~_2~_~L4~_5~R~r
instead of%28%2B%201%202%20%5B4%205%5D%29
which is only marginally better.Other mapping to try:
This would yield:
Note:
<
and>
still get url encoded, but some browsers (Chrome and Firefox at least) show them as the literal.Some ideas in this SO answer: https://stackoverflow.com/a/21976900/6264 http://xahlee.info/js/js_encodeURIComponent.html
Using + instead of %20 already seems to be supported and seems a quick win: https://stackoverflow.com/a/1211261/6264