2

I have users with slahes in their usernames. I want to give them easy urls such as /user/username even if their username is problematic. ie /user/xXx/superboy.

I'm using client side routing and I don't think there's any wildcard support. One obvious way to fix this would be to encode their username. href="/user/xXx%2Fsuperboy". But the browser automatically decodes the url when going to the link and then my router ends up not matching anyway. Is there some way to keep the browser from automatically decoding the url or any other way to solve my problem (perhaps a different decoding scheme?). Thanks.

I'm using angularjs with angular ui-router for routing.

5
  • If it is being decoded by browsers uniformly then why not try double encoding it? Commented Jun 10, 2013 at 6:34
  • What are you using on the server side? That's where you will have problems. AngularJS is not the issue here. For example if you are hosting your application in IIS you might have problems with such urls. Commented Jun 10, 2013 at 6:35
  • '/' character is not allowed in a file or folder name...how are you able to create such a file or folder in the first place. You could opt for passing the username as a querystring. Commented Jun 10, 2013 at 6:37
  • @PaulS could you give an example of double encoding? Commented Jun 10, 2013 at 6:52
  • @PaulS double encoding seems to work (rather well) when I tried it just now. I'll accept it if you put it as the answer. Also maybe you can explain how reliable this is and whether it's advisable... Commented Jun 10, 2013 at 7:00

1 Answer 1

2

Part 1.
Automatic decoding of URIs can be encounted in many situations, such as it being interpreted once then the interpretation passed on (to be re-interpreted).

Part 2.
In a path in a URI, / has a special meaning, so you can't use it as the name of a file or directory. This means if you're mapping something that isn't a real path to a path, you may end up with unexpected characters causing problems. To solve this the characters need to be encoded.

As you want to map usernames to a URI, you have to consider this might happen, so you have to encode in a way that allows for this. From your question, it looks like this happens once, so you'll need to double encode any part of the URI that isn't a "real URI path".

Also maybe you can explain how reliable this is and whether it's advisable

If you always have it used in the same way, it should be reliable. As for advisable, it would be much better to use the query part, rather than the path for this. href="/user?xXx/superboy" is a valid URI and you can get the query string easily (everything after first ?, or an inbuilt method). The only character you'd have to watch for is #, which has special meaning again.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.