clj-commons / secretary

A client-side router for ClojureScript.
773 stars 64 forks source link

Secretary doesn't comply to URL syntax specification #91

Open piotr-yuxuan opened 7 years ago

piotr-yuxuan commented 7 years ago

Hiya there,

First of all, thank you very much for that piece of free software :-) I've been using happily for a long time and it works well expect for this edge case which has been rather painful for me. To the best of my knowledge there is no issue about this so I fill this one just to reference this behaviour.

According to Wikipedia (and explained in a very circumlocutory way on https://url.spec.whatwg.org/) the syntax of a URL is :

scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]

However, when secretary is used without html5 routing the in-app route is stored in the fragment and then the query part is added. Reasons for this are obvious (legibility) but resulting URL respect no longer the syntax. Instead, they use this custom syntax:

scheme:[//[user:password@]host[:port]][/]path[#fragment][?query]

Using this custom syntax will cause Secretary and Standard libraries to firmly disagree on some painful edge cases, e.g. :

https://www.example.com/path/of/app#path/inside/app?query=params&as=defined&by=secretary

Of course, a very naive regex will get us data we need:

(def hash-according-to-secretary-syntax
  (comp second (partial re-find #"\#([^?]*)"))

I just wonder if you could add tiny functions somewhere in a utility namespace to allow Secretary's users to access fragment and query as meant by the custom syntax used. If you agree with this but don't have much time to spare on this detail, just give me general directions about where / how put new code and I'll be happy to do that.

gf3 commented 7 years ago

this certainly makes sense to me; unfortunately i definitely don't have time to address something like this anytime soon

piotr-yuxuan commented 7 years ago

Yeah, we all have either ideas but no time or time but no ideas ^^ I would happen to have not much time and even fewer ideas but I'd be glad to give it a try and see if I can contribute on that.

However I think it's enough to merely add some words about that in the readme. I issued a pull request for that.

(by the way https://github.com/gf3/secretary/pull/84 was about the same behaviour).