Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with route.js in jmvc-3.2.1 #102

Open
suryapavan opened this issue Dec 15, 2011 · 8 comments
Open

Issues with route.js in jmvc-3.2.1 #102

suryapavan opened this issue Dec 15, 2011 · 8 comments

Comments

@suryapavan
Copy link

Hi,
I am facing few issues while working with $.route functionality. (jquery/dom/route/route.js)

(1)while getting data from url and (2) while setting the url

WHILE GETTING DATA FROM URL: ($.route.data._data)

I have set the route rule as $.route(':/var1');
And my url consists of a base64 encoded value. For eg: 'suryapavan' is encoded to "c3VyeWFwYXZhbg=="

Say, url is http://localhost/test/#!/c3VyeWFwYXZhbg==
Now, the $.route.data._data is having the key 'var1' with value "c3VyeWFwYXZhbg" (instead of "c3VyeWFwYXZhbg==")

Why these characters are being stripped?

WHILE SETTING THE URL:

I have a $.route rule as $.route(":var1/:var2");

But in the URL, if any of the values (val1 or val2) is having special characters like ". , /= etc", its not showing up.

I mean, for eg: var1 is given as "aaaa" and var2 is given as "bbbb/cccc"
the url is comming up as "#!aaaa/bbbb" (cccc in var2 is missing).
[ expected result: '#!aaaa/bbbb%2Fcccc' ]

This problem exists even in that example "jquery/dom/route/route.html"

Hope you understand my problems!

There may be something wrong with the escaping in route.js
Could anyone please help me.

My project was stuck-up abruptly due to these errors! and it has stopped the project delivery :(

-Thanks!

@polgfred
Copy link
Contributor

The reason you're having an issue with base64 is that $.route uses URL encoding to serialize its data, so the value is being split on '&' and '='. The base64 value needs to be URL escaped. How are you triggering the route change, with $.route.attr(), $.route.link() or by forming the link yourself?

@suryapavan
Copy link
Author

@polgfred, thanks for your reply..

I am not setting the URL from the code.
With some internal mechanism, URL is auto generated at serverside and will be sent in an email.
Forget about base64.. somehow, that emailed url has that special character "=". ( http://domain-name/testProj/#!/aaa== )
and as I have defined the route rule "$.route('/:var1');" that value "aaa==" HAS TO BE taken into variable "var1"
but instead, it is having the value "aaa" only..

But in my tests, i tried from firebug "$.route.attrs({var1:'aaa=='});" this statement has changed the $.route.data._data -> var1 to "aaa=="
and then '{$.route} change' has been fired ... and rest of the execution went AS EXPECTED!
But, as you said, if $.route uses URL-encoding to serialize its data and splits the data on &,= .. why it is working fine when i did it as above?

Please correct me if i am wrong!
and help me out from this issue....

BTW: Please clarify me about the 2nd issue also! (reg: setting the URL thing..)

-Thanks!

@andykant
Copy link
Contributor

If all of your hash changes are handled through the $.route.attr/attrs methods, it's handled automatically, but if you're setting the hash elsewhere you need to use encodeURIComponent('aaa===') or its equivalent in whichever backend language you're using to create that URL with properly escaped characters.

@suryapavan
Copy link
Author

Hmm.. it is not possible to change the server side services :(
So, I have done a workaround for this. After loading the page, I am geting the hash value mannually (window.location.hash) and by using $.route.attr/attrs, i am updating the values into $.route.data
Its all working fine now :)

But I couldnt find a solution for the second issue! (mentioned in my question, above)
Please can anyone help me? :(

@suryapavan
Copy link
Author

Can anyone help me, please? :(

@justinbmeyer
Copy link
Member

What's needed is a greedy url. So you can write:

$.route('/*var1');

The problem should be fixed in the latest.

@justinbmeyer
Copy link
Member

I've noticed that window.location.hash gives something slightly different that window.location.href ... this might be the trick that helps ...

@justinbmeyer
Copy link
Member

This is is fixed now in CanJS:

https://github.com/jupiterjs/canjs/blob/master/route/route.js#L382

I read from the href, not the hash (which is already decoded)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants