private static String urlDecode(String str) { return QueryStringDecoder.decodeComponent(str, CharsetUtil.UTF_8); }
/** * Decodes a bit of an URL encoded by a browser. * <p> * This is equivalent to calling {@link #decodeComponent(String, Charset)} * with the UTF-8 charset (recommended to comply with RFC 3986, Section 2). * @param s The string to decode (can be empty). * @return The decoded string, or {@code s} if there's nothing to decode. * If the string to decode is {@code null}, returns an empty string. * @throws IllegalArgumentException if the string contains a malformed * escape sequence. */ public static String decodeComponent(final String s) { return decodeComponent(s, HttpConstants.DEFAULT_CHARSET); }
private static boolean addParam(String s, int nameStart, int valueStart, int valueEnd, Map<String, List<String>> params, Charset charset) { if (nameStart >= valueEnd) { return false; } if (valueStart <= nameStart) { valueStart = valueEnd + 1; } String name = decodeComponent(s, nameStart, valueStart - 1, charset, false); String value = decodeComponent(s, valueStart, valueEnd, charset, false); List<String> values = params.get(name); if (values == null) { values = new ArrayList<String>(1); // Often there's only 1 value. params.put(name, values); } values.add(value); return true; }
/** * Decodes a bit of an URL encoded by a browser. * <p> * The string is expected to be encoded as per RFC 3986, Section 2. * This is the encoding used by JavaScript functions {@code encodeURI} * and {@code encodeURIComponent}, but not {@code escape}. For example * in this encoding, é (in Unicode {@code U+00E9} or in UTF-8 * {@code 0xC3 0xA9}) is encoded as {@code %C3%A9} or {@code %c3%a9}. * <p> * This is essentially equivalent to calling * {@link URLDecoder#decode(String, String)} * except that it's over 2x faster and generates less garbage for the GC. * Actually this function doesn't allocate any memory if there's nothing * to decode, the argument itself is returned. * @param s The string to decode (can be empty). * @param charset The charset to use to decode the string (should really * be {@link CharsetUtil#UTF_8}. * @return The decoded string, or {@code s} if there's nothing to decode. * If the string to decode is {@code null}, returns an empty string. * @throws IllegalArgumentException if the string contains a malformed * escape sequence. */ public static String decodeComponent(final String s, final Charset charset) { if (s == null) { return EMPTY_STRING; } return decodeComponent(s, 0, s.length(), charset, false); }
/** * Decode component * * @return the decoded component */ private static String decodeAttribute(String s, Charset charset) { try { return QueryStringDecoder.decodeComponent(s, charset); } catch (IllegalArgumentException e) { throw new ErrorDataDecoderException("Bad string: '" + s + '\'', e); } }
/** * Returns the decoded path string of the URI. */ public String path() { if (path == null) { path = decodeComponent(uri, 0, pathEndIdx(), charset, true); } return path; }
private Attribute getContentDispositionAttribute(String... values) { String name = cleanString(values[0]); String value = values[1]; // Filename can be token, quoted or encoded. See https://tools.ietf.org/html/rfc5987 if (HttpHeaderValues.FILENAME.contentEquals(name)) { // Value is quoted or token. Strip if quoted: int last = value.length() - 1; if (last > 0 && value.charAt(0) == HttpConstants.DOUBLE_QUOTE && value.charAt(last) == HttpConstants.DOUBLE_QUOTE) { value = value.substring(1, last); } } else if (FILENAME_ENCODED.equals(name)) { try { name = HttpHeaderValues.FILENAME.toString(); String[] split = value.split("'", 3); value = QueryStringDecoder.decodeComponent(split[2], Charset.forName(split[0])); } catch (ArrayIndexOutOfBoundsException e) { throw new ErrorDataDecoderException(e); } catch (UnsupportedCharsetException e) { throw new ErrorDataDecoderException(e); } } else { // otherwise we need to clean the value value = cleanString(value); } return factory.createAttribute(request, name, value); }
private static String urlDecode(String str) { return QueryStringDecoder.decodeComponent(str, CharsetUtil.UTF_8); }
@Override public Path resolve(final String path) { if (registeredPaths.size() == 1) { return registeredPaths.get(0); } String decodedPath; try { decodedPath = QueryStringDecoder.decodeComponent(path, Charset.defaultCharset()); } catch (IllegalArgumentException iae) { decodedPath = path; } int pieces = -1; Path bestPath = null; // TODO PERF: We must navigate from the longest path to the shortest to avoid counting pieces. for(Path registerPath : registeredPaths) { if (registerPath.getPattern().matcher(decodedPath).lookingAt()) { int split = registerPath.getPath().split(URL_PATH_SEPARATOR).length; if (split > pieces) { pieces = split; bestPath = registerPath; } } } return bestPath; }
/** * Returns the decoded path string of the URI. */ public String path() { if (path == null) { path = decodeComponent(uri, 0, pathEndIdx(), charset, true); } return path; }
/** * Decode component * * @return the decoded component */ private static String decodeAttribute(String s, Charset charset) { try { return QueryStringDecoder.decodeComponent(s, charset); } catch (IllegalArgumentException e) { throw new ErrorDataDecoderException("Bad string: '" + s + '\'', e); } }
/** * Decode component * * @return the decoded component */ private static String decodeAttribute(String s, Charset charset) { try { return QueryStringDecoder.decodeComponent(s, charset); } catch (IllegalArgumentException e) { throw new ErrorDataDecoderException("Bad string: '" + s + '\'', e); } }
/** * Returns the decoded path string of the URI. */ public String path() { if (path == null) { path = decodeComponent(uri, 0, pathEndIdx(), charset, true); } return path; }
/** * Decode component * * @return the decoded component */ private static String decodeAttribute(String s, Charset charset) { try { return QueryStringDecoder.decodeComponent(s, charset); } catch (IllegalArgumentException e) { throw new ErrorDataDecoderException("Bad string: '" + s + '\'', e); } }
public QueryStringDecoder(String uri) { if (null == uri) { throw new NullPointerException("Uri can not be null."); } this.uri = uri; uri = io.netty.handler.codec.http.QueryStringDecoder.decodeComponent(uri); if (!uri.endsWith("/") && !uri.contains(".") && !uri.contains("?")) { // Normalize the URI for better matching of Servlet style URI constraints. uri += "/"; } nettyDecoder = new io.netty.handler.codec.http.QueryStringDecoder(uri); }
public QueryStringDecoder(String uri) { if (null == uri) { throw new NullPointerException("Uri can not be null."); } this.uri = uri; uri = io.netty.handler.codec.http.QueryStringDecoder.decodeComponent(uri); if (!uri.endsWith("/") && !uri.contains(".") && !uri.contains("?")) { // Normalize the URI for better matching of Servlet style URI constraints. uri += "/"; } nettyDecoder = new io.netty.handler.codec.http.QueryStringDecoder(uri); }
/** * Decode component * * @return the decoded component */ private static String decodeAttribute(String s, Charset charset) { try { return QueryStringDecoder.decodeComponent(s, charset); } catch (IllegalArgumentException e) { throw new ErrorDataDecoderException("Bad string: '" + s + '\'', e); } }
private String decodeURIComponent(String s) { try { return QueryStringDecoder.decodeComponent(s.replace("+", "%2B")); } catch (IllegalArgumentException cause) { throw new InvalidPathEncodingException(cause); } }
/** * Returns the decoded path string of the URI. */ public String path() { if (path == null) { path = decodeComponent(uri, 0, pathEndIdx(), charset, true); } return path; }
/** * Returns the decoded path string of the URI. */ public String path() { if (path == null) { path = decodeComponent(uri, 0, pathEndIdx(), charset, true); } return path; }