Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • There is a small set of characters that are allowed in URLs. Everything else must be encoded. You may be better off having only two branches, one for allowed characters, the other to escape, using some simple way to get the hex value of the character (the encoding is not dark magic, it's just the hex value, %20 is 0x20 which is a space in ASCII and UTF-8). See stackoverflow.com/a/10660730/1079308 Commented Jan 8, 2013 at 19:20
  • Thanks! Reducing the number of if branches speeded up the encoding dramatically to the point it's sufficient for my use case. However, I'm still unable to encode certain characters like "$$" or "\". Would really appreciate an advice on how to escape the content of the variable properly. Commented Jan 8, 2013 at 21:46
  • Note that I've updated my answer: my first versions were all forking an external [ utility on my router. Avoiding the external [ is a significant speed improvement. Commented Jan 9, 2013 at 11:29