"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "httpclient/src/main/java/org/apache/http/client/utils/URLEncodedUtils.java" between
httpcomponents-client-4.5.7-src.tar.gz and httpcomponents-client-4.5.8-src.tar.gz

About: HttpComponents is an Apache project responsible for creating and maintaining a toolset of low level Java components focused on HTTP and associated protocols. Java sources.

URLEncodedUtils.java  (httpcomponents-client-4.5.7-src):URLEncodedUtils.java  (httpcomponents-client-4.5.8-src)
skipping to change at line 39 skipping to change at line 39
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.net.URI; import java.net.URI;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet; import java.util.BitSet;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import org.apache.http.Consts; import org.apache.http.Consts;
import org.apache.http.Header; import org.apache.http.Header;
import org.apache.http.HeaderElement; import org.apache.http.HeaderElement;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
import org.apache.http.entity.ContentType; import org.apache.http.entity.ContentType;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
skipping to change at line 71 skipping to change at line 73
public class URLEncodedUtils { public class URLEncodedUtils {
/** /**
* The default HTML form content type. * The default HTML form content type.
*/ */
public static final String CONTENT_TYPE = "application/x-www-form-urlencoded "; public static final String CONTENT_TYPE = "application/x-www-form-urlencoded ";
private static final char QP_SEP_A = '&'; private static final char QP_SEP_A = '&';
private static final char QP_SEP_S = ';'; private static final char QP_SEP_S = ';';
private static final String NAME_VALUE_SEPARATOR = "="; private static final String NAME_VALUE_SEPARATOR = "=";
private static final char PATH_SEPARATOR = '/';
private static final BitSet PATH_SEPARATORS = new BitSet(256);
static {
PATH_SEPARATORS.set(PATH_SEPARATOR);
}
/** /**
* @deprecated 4.5 Use {@link #parse(URI, Charset)} * @deprecated 4.5 Use {@link #parse(URI, Charset)}
*/ */
@Deprecated @Deprecated
public static List <NameValuePair> parse(final URI uri, final String charset Name) { public static List <NameValuePair> parse(final URI uri, final String charset Name) {
return parse(uri, charsetName != null ? Charset.forName(charsetName) : n ull); return parse(uri, charsetName != null ? Charset.forName(charsetName) : n ull);
} }
/** /**
* Returns a list of {@link NameValuePair NameValuePairs} as built from the * Returns a list of {@link NameValuePair}s URI query parameters.
URI's query portion. For example, a URI * By convention, {@code '&'} and {@code ';'} are accepted as parameter sepa
* of {@code http://example.org/path/to/file?a=1&b=2&c=3} would return a lis rators.
t of three NameValuePairs, one for a=1,
* one for b=2, and one for c=3. By convention, {@code '&'} and {@code ';'}
are accepted as parameter separators.
* <p>
* This is typically useful while parsing an HTTP PUT.
* *
* This API is currently only used for testing. * @param uri input URI.
* * @param charset parameter charset.
* @param uri * @return list of query parameters.
* URI to parse
* @param charset
* Charset to use while parsing the query
* @return a list of {@link NameValuePair} as built from the URI's query por
tion.
* *
* @since 4.5 * @since 4.5
*/ */
public static List <NameValuePair> parse(final URI uri, final Charset charse t) { public static List <NameValuePair> parse(final URI uri, final Charset charse t) {
Args.notNull(uri, "URI"); Args.notNull(uri, "URI");
final String query = uri.getRawQuery(); final String query = uri.getRawQuery();
if (query != null && !query.isEmpty()) { if (query != null && !query.isEmpty()) {
return parse(query, charset); return parse(query, charset);
} }
return createEmptyList(); return createEmptyList();
skipping to change at line 233 skipping to change at line 234
value = decodeFormFields(token.substring(i + 1).trim(), charset) ; value = decodeFormFields(token.substring(i + 1).trim(), charset) ;
} else { } else {
name = decodeFormFields(token.trim(), charset); name = decodeFormFields(token.trim(), charset);
value = null; value = null;
} }
parameters.add(new BasicNameValuePair(name, value)); parameters.add(new BasicNameValuePair(name, value));
} }
} }
/** /**
* Returns a list of {@link NameValuePair NameValuePairs} as parsed from the * Returns a list of {@link NameValuePair}s URI query parameters.
given string using the given character * By convention, {@code '&'} and {@code ';'} are accepted as parameter sepa
* encoding. By convention, {@code '&'} and {@code ';'} are accepted as para rators.
meter separators.
* *
* @param s * @param s URI query component.
* text to parse. * @param charset charset to use when decoding the parameters.
* @param charset * @return list of query parameters.
* Encoding to use when decoding the parameters.
* @return a list of {@link NameValuePair} as built from the URI's query por
tion.
* *
* @since 4.2 * @since 4.2
*/ */
public static List<NameValuePair> parse(final String s, final Charset charse t) { public static List<NameValuePair> parse(final String s, final Charset charse t) {
if (s == null) { if (s == null) {
return createEmptyList(); return createEmptyList();
} }
final CharArrayBuffer buffer = new CharArrayBuffer(s.length()); final CharArrayBuffer buffer = new CharArrayBuffer(s.length());
buffer.append(s); buffer.append(s);
return parse(buffer, charset, QP_SEP_A, QP_SEP_S); return parse(buffer, charset, QP_SEP_A, QP_SEP_S);
} }
/** /**
* Returns a list of {@link NameValuePair NameValuePairs} as parsed from the given string using the given character * Returns a list of {@link NameValuePair NameValuePairs} as parsed from the given string using the given character
* encoding. * encoding.
* *
* @param s * @param s input text.
* text to parse. * @param charset parameter charset.
* @param charset * @param separators parameter separators.
* Encoding to use when decoding the parameters. * @return list of query parameters.
* @param separators
* element separators.
* @return a list of {@link NameValuePair} as built from the URI's query por
tion.
* *
* @since 4.3 * @since 4.3
*/ */
public static List<NameValuePair> parse(final String s, final Charset charse t, final char... separators) { public static List<NameValuePair> parse(final String s, final Charset charse t, final char... separators) {
if (s == null) { if (s == null) {
return createEmptyList(); return createEmptyList();
} }
final CharArrayBuffer buffer = new CharArrayBuffer(s.length()); final CharArrayBuffer buffer = new CharArrayBuffer(s.length());
buffer.append(s); buffer.append(s);
return parse(buffer, charset, separators); return parse(buffer, charset, separators);
} }
/** /**
* Returns a list of {@link NameValuePair NameValuePairs} as parsed from the * Returns a list of {@link NameValuePair}s parameters.
given string using
* the given character encoding.
* *
* @param buf * @param buf
* text to parse. * text to parse.
* @param charset * @param charset
* Encoding to use when decoding the parameters. * Encoding to use when decoding the parameters.
* @param separators * @param separators
* element separators. * element separators.
* @return a list of {@link NameValuePair} as built from the URI's query por tion. * @return a list of {@link NameValuePair} as built from the URI's query por tion.
* *
* @since 4.4 * @since 4.4
skipping to change at line 324 skipping to change at line 319
} }
if (!name.isEmpty()) { if (!name.isEmpty()) {
list.add(new BasicNameValuePair( list.add(new BasicNameValuePair(
decodeFormFields(name, charset), decodeFormFields(name, charset),
decodeFormFields(value, charset))); decodeFormFields(value, charset)));
} }
} }
return list; return list;
} }
static List<String> splitSegments(final CharSequence s, final BitSet separat
ors) {
final ParserCursor cursor = new ParserCursor(0, s.length());
// Skip leading separator
if (cursor.atEnd()) {
return Collections.emptyList();
}
if (separators.get(s.charAt(cursor.getPos()))) {
cursor.updatePos(cursor.getPos() + 1);
}
final List<String> list = new ArrayList<String>();
final StringBuilder buf = new StringBuilder();
for (;;) {
if (cursor.atEnd()) {
list.add(buf.toString());
break;
}
final char current = s.charAt(cursor.getPos());
if (separators.get(current)) {
list.add(buf.toString());
buf.setLength(0);
} else {
buf.append(current);
}
cursor.updatePos(cursor.getPos() + 1);
}
return list;
}
static List<String> splitPathSegments(final CharSequence s) {
return splitSegments(s, PATH_SEPARATORS);
}
/**
* Returns a list of URI path segments.
*
* @param s URI path component.
* @param charset parameter charset.
* @return list of segments.
*
* @since 4.5
*/
public static List<String> parsePathSegments(final CharSequence s, final Cha
rset charset) {
Args.notNull(s, "Char sequence");
final List<String> list = splitPathSegments(s);
for (int i = 0; i < list.size(); i++) {
list.set(i, urlDecode(list.get(i), charset != null ? charset : Const
s.UTF_8, false));
}
return list;
}
/**
* Returns a list of URI path segments.
*
* @param s URI path component.
* @return list of segments.
*
* @since 4.5
*/
public static List<String> parsePathSegments(final CharSequence s) {
return parsePathSegments(s, Consts.UTF_8);
}
/**
* Returns a string consisting of joint encoded path segments.
*
* @param segments the segments.
* @param charset parameter charset.
* @return URI path component
*
* @since 4.5
*/
public static String formatSegments(final Iterable<String> segments, final C
harset charset) {
Args.notNull(segments, "Segments");
final StringBuilder result = new StringBuilder();
for (final String segment : segments) {
result.append(PATH_SEPARATOR).append(urlEncode(segment, charset, PAT
HSAFE, false));
}
return result.toString();
}
/**
* Returns a string consisting of joint encoded path segments.
*
* @param segments the segments.
* @return URI path component
*
* @since 4.5
*/
public static String formatSegments(final String... segments) {
return formatSegments(Arrays.asList(segments), Consts.UTF_8);
}
/** /**
* Returns a String that is suitable for use as an {@code application/x-www- form-urlencoded} * Returns a String that is suitable for use as an {@code application/x-www- form-urlencoded}
* list of parameters in an HTTP PUT or HTTP POST. * list of parameters in an HTTP PUT or HTTP POST.
* *
* @param parameters The parameters to include. * @param parameters The parameters to include.
* @param charset The encoding to use. * @param charset The encoding to use.
* @return An {@code application/x-www-form-urlencoded} string * @return An {@code application/x-www-form-urlencoded} string
*/ */
public static String format( public static String format(
final List <? extends NameValuePair> parameters, final List <? extends NameValuePair> parameters,
skipping to change at line 456 skipping to change at line 543
* <a href="http://www.ietf.org/rfc/rfc2732.txt">RFC 2732</a> * <a href="http://www.ietf.org/rfc/rfc2732.txt">RFC 2732</a>
*/ */
private static final BitSet RESERVED = new BitSet(256); private static final BitSet RESERVED = new BitSet(256);
/** /**
* Safe characters for x-www-form-urlencoded data, as per java.net.URLEncode r and browser behaviour, * Safe characters for x-www-form-urlencoded data, as per java.net.URLEncode r and browser behaviour,
* i.e. alphanumeric plus {@code "-", "_", ".", "*"} * i.e. alphanumeric plus {@code "-", "_", ".", "*"}
*/ */
private static final BitSet URLENCODER = new BitSet(256); private static final BitSet URLENCODER = new BitSet(256);
private static final BitSet PATH_SPECIAL = new BitSet(256);
static { static {
// unreserved chars // unreserved chars
// alpha characters // alpha characters
for (int i = 'a'; i <= 'z'; i++) { for (int i = 'a'; i <= 'z'; i++) {
UNRESERVED.set(i); UNRESERVED.set(i);
} }
for (int i = 'A'; i <= 'Z'; i++) { for (int i = 'A'; i <= 'Z'; i++) {
UNRESERVED.set(i); UNRESERVED.set(i);
} }
// numeric characters // numeric characters
skipping to change at line 493 skipping to change at line 582
PUNCT.set('$'); PUNCT.set('$');
PUNCT.set('&'); PUNCT.set('&');
PUNCT.set('+'); PUNCT.set('+');
PUNCT.set('='); PUNCT.set('=');
// Safe for userinfo // Safe for userinfo
USERINFO.or(UNRESERVED); USERINFO.or(UNRESERVED);
USERINFO.or(PUNCT); USERINFO.or(PUNCT);
// URL path safe // URL path safe
PATHSAFE.or(UNRESERVED); PATHSAFE.or(UNRESERVED);
PATHSAFE.set('/'); // segment separator
PATHSAFE.set(';'); // param separator PATHSAFE.set(';'); // param separator
PATHSAFE.set(':'); // rest as per list in 2396, i.e. : @ & = + $ , PATHSAFE.set(':'); // RFC 2396
PATHSAFE.set('@'); PATHSAFE.set('@');
PATHSAFE.set('&'); PATHSAFE.set('&');
PATHSAFE.set('='); PATHSAFE.set('=');
PATHSAFE.set('+'); PATHSAFE.set('+');
PATHSAFE.set('$'); PATHSAFE.set('$');
PATHSAFE.set(','); PATHSAFE.set(',');
PATH_SPECIAL.or(PATHSAFE);
PATH_SPECIAL.set('/');
RESERVED.set(';'); RESERVED.set(';');
RESERVED.set('/'); RESERVED.set('/');
RESERVED.set('?'); RESERVED.set('?');
RESERVED.set(':'); RESERVED.set(':');
RESERVED.set('@'); RESERVED.set('@');
RESERVED.set('&'); RESERVED.set('&');
RESERVED.set('='); RESERVED.set('=');
RESERVED.set('+'); RESERVED.set('+');
RESERVED.set('$'); RESERVED.set('$');
RESERVED.set(','); RESERVED.set(',');
skipping to change at line 685 skipping to change at line 776
* *
* @param content the string to encode, does not convert space to '+' * @param content the string to encode, does not convert space to '+'
* @param charset the charset to use * @param charset the charset to use
* @return the encoded string * @return the encoded string
*/ */
static String encUric(final String content, final Charset charset) { static String encUric(final String content, final Charset charset) {
return urlEncode(content, charset, URIC, false); return urlEncode(content, charset, URIC, false);
} }
/** /**
* Encode a String using the {@link #PATHSAFE} set of characters. * Encode a String using the {@link #PATH_SPECIAL} set of characters.
* <p> * <p>
* Used by URIBuilder to encode path segments. * Used by URIBuilder to encode path segments.
* *
* @param content the string to encode, does not convert space to '+' * @param content the string to encode, does not convert space to '+'
* @param charset the charset to use * @param charset the charset to use
* @return the encoded string * @return the encoded string
*/ */
static String encPath(final String content, final Charset charset) { static String encPath(final String content, final Charset charset) {
return urlEncode(content, charset, PATHSAFE, false); return urlEncode(content, charset, PATH_SPECIAL, false);
} }
} }
 End of changes. 16 change blocks. 
41 lines changed or deleted 130 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)