I'm writing a Java app that is accepting URL parameter values that may or may not be encoded. I need an easy way to tell whether or not I need to encode the parameter string.
In other words, I want a function boolean needsEncoding(String param)
, which will return true if I pass in the String "[email protected]", and false if I pass in "foo%40test.com". The problem with this idea is that this is ambiguous. How would I know whether or not the "%" sign in the latter string should be encoded? One way to handle this is to modify my contract - require clients to pass in un-encoded strings so that I know I always need to encode them. Thoughts?