jericho 2002/10/26 08:34:32 Modified: httpclient/src/java/org/apache/commons/httpclient URI.java httpclient/src/java/org/apache/commons/httpclient/util URIUtil.java Log: - Fix a bug of String encodeWithinQuery(unescaped). Sorry about that. --;;; It called the encodeQuery(unescaped, charset) method. It should call the encodeWithinQuery(unescaped, charset) method. :( - Fix and add javadoc message in URI class - Add the BitSet of the allowed chracters within the userinfo, path and query component. It specify the explicit reserverd characters. Revision Changes Path 1.8 +56 -15 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URI.java Index: URI.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URI.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- URI.java 23 Oct 2002 01:35:49 -0000 1.7 +++ URI.java 26 Oct 2002 15:34:32 -0000 1.8 @@ -1306,10 +1306,10 @@ disallowed_opaque_part.andNot(opaque_part); } - // ------------------------------- Characters allowed within each component + // ----------------------- Characters allowed within and for each component /** - * Those characters that are allowed within the authority component. + * Those characters that are allowed for the authority component. */ public static final BitSet allowed_authority = new BitSet(256); // Static initializer for allowed_authority @@ -1320,7 +1320,7 @@ /** - * Those characters that are allowed within the opaque_part. + * Those characters that are allowed for the opaque_part. */ public static final BitSet allowed_opaque_part = new BitSet(256); // Static initializer for allowed_opaque_part @@ -1331,7 +1331,7 @@ /** - * Those characters that are allowed within the reg_name. + * Those characters that are allowed for the reg_name. */ public static final BitSet allowed_reg_name = new BitSet(256); // Static initializer for allowed_reg_name @@ -1343,7 +1343,7 @@ /** - * Those characters that are allowed within the userinfo component. + * Those characters that are allowed for the userinfo component. */ public static final BitSet allowed_userinfo = new BitSet(256); // Static initializer for allowed_userinfo @@ -1355,7 +1355,7 @@ /** - * Those characters that are allowed within the IPv6reference component. + * Those characters that are for within the IPv6reference component. * The characters '[', ']' in IPv6reference should be excluded. */ public static final BitSet allowed_IPv6reference = new BitSet(256); @@ -1369,7 +1369,7 @@ /** - * Those characters that are allowed within the host component. + * Those characters that are allowed for the host component. * The characters '[', ']' in IPv6reference should be excluded. */ public static final BitSet allowed_host = new BitSet(256); @@ -1381,7 +1381,23 @@ /** - * Those characters that are allowed within the abs_path. + * Those characters that are allowed for the authority component. + */ + public static final BitSet allowed_within_authority = new BitSet(256); + // Static initializer for allowed_within_authority + static { + allowed_within_authority.or(server); + allowed_within_authority.or(reg_name); + allowed_within_authority.clear(';'); + allowed_within_authority.clear(':'); + allowed_within_authority.clear('@'); + allowed_within_authority.clear('?'); + allowed_within_authority.clear('/'); + } + + + /** + * Those characters that are allowed for the abs_path. */ public static final BitSet allowed_abs_path = new BitSet(256); // Static initializer for allowed_abs_path @@ -1393,7 +1409,7 @@ /** - * Those characters that are allowed within the rel_path. + * Those characters that are allowed for the rel_path. */ public static final BitSet allowed_rel_path = new BitSet(256); // Static initializer for allowed_rel_path @@ -1404,7 +1420,21 @@ /** - * Those characters that are allowed within the query component. + * Those characters that are allowed within the path. + */ + public static final BitSet allowed_within_path = new BitSet(256); + // Static initializer for allowed_within_path + static { + allowed_within_path.or(abs_path); + allowed_within_path.clear('/'); + allowed_within_path.clear(';'); + allowed_within_path.clear('='); + allowed_within_path.clear('?'); + } + + + /** + * Those characters that are allowed for the query component. */ public static final BitSet allowed_query = new BitSet(256); // Static initializer for allowed_query @@ -1415,7 +1445,18 @@ /** - * Those characters that are allowed within the fragment component. + * Those characters that are allowed within the query component. + */ + public static final BitSet allowed_within_query = new BitSet(256); + // Static initializer for allowed_within_query + static { + allowed_within_query.or(allowed_query); + allowed_within_query.andNot(reserved); // excluded 'reserved' + } + + + /** + * Those characters that are allowed for the fragment component. */ public static final BitSet allowed_fragment = new BitSet(256); // Static initializer for allowed_fragment 1.8 +97 -22 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java Index: URIUtil.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- URIUtil.java 25 Oct 2002 10:15:52 -0000 1.7 +++ URIUtil.java 26 Oct 2002 15:34:32 -0000 1.8 @@ -83,17 +83,6 @@ protected static final BitSet empty = new BitSet(1); - protected static final BitSet allowed_in_query = new BitSet(256); - // Static initializer for allowed_in_query - static { - allowed_in_query.or(URI.allowed_query); - allowed_in_query.clear('?'); - allowed_in_query.clear('='); - allowed_in_query.clear('&'); - allowed_in_query.clear('#'); - allowed_in_query.clear('+'); - } - // ---------------------------------------------------------- URI utilities /** @@ -240,6 +229,45 @@ /** + * Escape and encode a string regarded as within the authority component of + * an URI with the default protocol charset. + * Within the authority component, the characters ";", ":", "@", "?", and + * "/" are reserved. + * + * @param unescaped an unescaped string + * @param charset the charset + * @return the escaped string + * @exception URIException + * @see URI#getProtocolCharset + * @see #encode + */ + public static String encodeWithinAuthority(String unescaped) + throws URIException { + + return encodeWithinAuthority(unescaped, URI.getProtocolCharset()); + } + + + /** + * Escape and encode a string regarded as within the authority component of + * an URI with a given charset. + * Within the authority component, the characters ";", ":", "@", "?", and + * "/" are reserved. + * + * @param unescaped an unescaped string + * @param charset the charset + * @return the escaped string + * @exception URIException + * @see #encode + */ + public static String encodeWithinAuthority(String unescaped, String charset) + throws URIException { + + return encode(unescaped, URI.allowed_within_authority, charset); + } + + + /** * Escape and encode a string regarded as the path and query components of * an URI with the default protocol charset. * @@ -280,6 +308,47 @@ /** + * Escape and encode a string regarded as within the path component of an + * URI with the default protocol charset. + * The path may consist of a sequence of path segments separated by a + * single slash "/" character. Within a path segment, the characters + * "/", ";", "=", and "?" are reserved. + * + * @param unescaped an unescaped string + * @param charset the charset + * @return the escaped string + * @exception URIException + * @see URI#getProtocolCharset + * @see #encode + */ + public static String encodeWithinPath(String unescaped) + throws URIException { + + return encodeWithinPath(unescaped, URI.getProtocolCharset()); + } + + + /** + * Escape and encode a string regarded as within the path component of an + * URI with a given charset. + * The path may consist of a sequence of path segments separated by a + * single slash "/" character. Within a path segment, the characters + * "/", ";", "=", and "?" are reserved. + * + * @param unescaped an unescaped string + * @param charset the charset + * @return the escaped string + * @exception URIException + * @see #encode + */ + public static String encodeWithinPath(String unescaped, String charset) + throws URIException { + + return encode(unescaped, URI.allowed_within_path, charset); + } + + + /** * Escape and encode a string regarded as the path component of an URI with * the default protocol charset. * @@ -313,8 +382,10 @@ /** - * Escape and encode a string regarded as inside the query component of an + * Escape and encode a string regarded as within the query component of an * URI with the default protocol charset. + * Within a query component, the characters ";", "/", "?", ":", "@", "&", + * "=", "+", ",", and "$" are reserved. * * @param unescaped an unescaped string * @return the escaped string @@ -322,14 +393,18 @@ * @see URI#getProtocolCharset * @see #encode */ - public static String encodeInQuery(String unescaped) throws URIException { - return encodeQuery(unescaped, URI.getProtocolCharset()); + public static String encodeWithinQuery(String unescaped) + throws URIException { + + return encodeWithinQuery(unescaped, URI.getProtocolCharset()); } /** - * Escape and encode a string regarded as inside the query component of an + * Escape and encode a string regarded as within the query component of an * URI with a given charset. + * Within a query component, the characters ";", "/", "?", ":", "@", "&", + * "=", "+", ",", and "$" are reserved. * * @param unescaped an unescaped string * @param charset the charset @@ -337,10 +412,10 @@ * @exception URIException * @see #encode */ - public static String encodeInQuery(String unescaped, String charset) + public static String encodeWithinQuery(String unescaped, String charset) throws URIException { - return encode(unescaped, allowed_in_query, charset); + return encode(unescaped, URI.allowed_within_query, charset); } @@ -372,7 +447,7 @@ public static String encodeQuery(String unescaped, String charset) throws URIException { - return encode(unescaped, allowed_in_query, charset); + return encode(unescaped, URI.allowed_query, charset); }
-- To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>