Java URI class: constructor determines whether or not query is encoded? -
is behavior intentional?
//create same uri using 2 different constructors uri foo = null, bar = null; try { //constructor: uri(uri string) foo = new uri("http://localhost/index.php?token=4%2f4ezdssbg_4vx6d5pzvdsmldoyitb"); } catch (urisyntaxexception e) {} try { //constructor: uri(scheme, authority, path, query, fragment) bar = new uri("http", "localhost", "/index.php", "token=4%2f4ezdssbg_4vx6d5pzvdsmldoyitb", null); } catch (urisyntaxexception e) {} //the output: //foo.getquery() = token=4/4ezdssbg_4vx6d5pzvdsmldoyitb //bar.getquery() = token=4%2f4ezdssbg_4vx6d5pzvdsmldoyitb the uri(string uri) constructor seems decoding query part of uri. thought query portion supposed encoded? , why doesn't other constructor decode query part?
from uri javadoc:
the single-argument constructor requires illegal characters in argument quoted , preserves escaped octets , other characters present.
the multi-argument constructors quote illegal characters required components in appear. percent character ('%') quoted these constructors. other characters preserved.
thus uri(string) expects encode correctly , assumes %2f such encoded octed decoded /.
the other constructors endcode % character (resulting in %252f input %2f) , after decoding still %2f.
i assume purpose of deviation between constructors allow things new uri(otheruri.tostring()) tostring() returning encoded uri.
Comments
Post a Comment