borkdude / re-find.web

Web version of re-find
https://borkdude.github.io/re-find.web
Eclipse Public License 1.0
25 stars 4 forks source link

Prettify URLS #67

Open borkdude opened 5 years ago

borkdude commented 5 years ago

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:

< > => ~< ~>
_ => ~_
space => _
( ) => < >
, => ~,
: => ,

This would yield:

<%2B_1_2%5B3_4_5%5D>

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

borkdude commented 5 years ago

Good candidate for optimization:

https://re-find.it/?args=%7B%3Aa%201%20%3Ab%202%20%3Ac%203%7D%20%5B%3Ab%20%3Ac%5D&ret=%7B%3Aa%201%7D&more=true

wagjo commented 5 years ago

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.

borkdude commented 5 years ago

@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.