java.lang.String encodeForURL(java.lang.String input) throws EncodingException
Encode for use in a URL. This method performs URL encoding on the entire string.
For the docs the "URL encoding" is defined by referencing wikipedia !
http://en.wikipedia.org/wiki/Percent-encoding
Don't we have RFCs for this ?
Being curious what it really does ? Look in the code:
return java.net.URLEncoder.encode(input,
ESAPI.securityConfiguration().getCharacterEncoding());
What ? Read JavaDoc !
Translates a string into application/x-www-form-urlencoded format.This is not ment for building URLs but for encoding form data !
There is another JavaDoc:
The URLEncoder and URLDecoder classes can also be used,And another one:
but only for HTML form encoding,
which is not the same as the encoding scheme defined in RFC2396.
The recommended way to manage the encoding and decoding of URLs is to use URI
Reading URI docs you will learn about all deviations Java has from RFC2396.
javase/6/docs/api/java/net/URI.html
The OWASP JavaScript version of "the same" is even "better"
(I bet a beer, not producing the same results as Java code):
encodeForURL: function(sInput) {
return !sInput ? null : escape(sInput);
}
Reading MDC docs:
escape and unescape Functions
The escape and unescape functions do not work properly for non-ASCII characters
and have been deprecated. In JavaScript 1.5
and later, use encodeURI, decodeURI, encodeURIComponent, and decodeURIComponent.
Bad naming or ignorance ?
There is just small chance that authors realy ment to code"HTML form encoding" and not to solve URI building and encoding,
and that the method has just a bad name. I would suggest Encoder.encodeForHtmlForm
instead of misleading encodeForURL with even more confisung wiki link !
In the case OWASP really ment to solve
encoding for URI or http scheme URLs, there should be totaly
another code behind !!!!
If you really plan to encode URI components there is API needed to
encode path, path-segment, query, fragment with separate rules defined by
RFC (and I vote for the "new rfc3986" instead of buggy java implementation of old "RFC2396").
If you code or find rfc3986 compliant java uri implementation,
let me know,
until then I will not
replace my code for UNRELIABLE OWASP REFERENCE IMPLEMENTATION.
Strong suggestion again: search for "Jena IRI".