/** * Decode the http request represented by the bytes inside {@link MessageBytes} * using an {@link UDecoder}. * @param decodedURI - The bytes to decode * @param urlDecoder - The urlDecoder to use to decode. * @throws java.lang.Exception */ public static void decode(final MessageBytes decodedURI, final UDecoder urlDecoder) throws Exception { decode(decodedURI, urlDecoder, null, null); }
/** * Normalize URI. * <p> * This method normalizes "\", "//", "/./" and "/../". This method will * return false when trying to go above the root, or if the URI contains * a null byte. * * @param dataChunk URI to be normalized * @return <tt>true</tt> if normalization was successful, or <tt>false</tt> otherwise */ public static boolean normalize(final DataChunk dataChunk) { switch (dataChunk.getType()) { case Bytes: return normalizeBytes(dataChunk.getByteChunk()); case Buffer: return normalizeBuffer(dataChunk.getBufferChunk()); case String: try { dataChunk.toChars(null); } catch (CharConversionException unexpected) { // should never occur throw new IllegalStateException("Unexpected exception", unexpected); } // pass to Chars case case Chars: return normalizeChars(dataChunk.getCharChunk()); default: throw new NullPointerException(); } }
/** * Decode the HTTP request represented by the bytes inside {@link MessageBytes} * using an {@link UDecoder}, using the specified encoding, using the specified * [@link B2CConverter} to decode the request. * @param decodedURI - The bytes to decode * @param urlDecoder - The urlDecoder to use to decode. * @param encoding the encoding value, default is UTF-8. * @param b2cConverter the Bytes to Char Converter. * @throws java.lang.Exception */ public static void decode(final MessageBytes decodedURI, final UDecoder urlDecoder, String encoding, final B2CConverter b2cConverter) throws Exception { // %xx decoding of the URL urlDecoder.convert(decodedURI, false); if (!normalize(decodedURI)) { throw new IOException("Invalid URI character encoding"); } if (encoding == null) { encoding = "utf-8"; } convertURI(decodedURI, encoding, b2cConverter); // Check that the URI is still normalized if (!checkNormalize(decodedURI.getCharChunk())) { throw new IOException("Invalid URI character encoding"); } }
/** * Normalize URI. * <p> * This method normalizes "\", "//", "/./" and "/../". This method will * return false when trying to go above the root, or if the URI contains * a null byte. * * @param uriMB URI to be normalized * @return <tt>true</tt> if normalization was successful, or <tt>false</tt> otherwise */ public static boolean normalize(MessageBytes uriMB) { int type = uriMB.getType(); if (type == MessageBytes.T_CHARS) { return normalizeChars(uriMB.getCharChunk()); } else { return normalizeBytes(uriMB.getByteChunk()); } }
/** * Decode the HTTP request represented by the bytes inside {@link DataChunk}. * @param originalURI - The bytes to decode * @param targetDecodedURI the target {@link DataChunk} URI will be decoded to * @param isSlashAllowed is '/' an allowable character * @param encoding the encoding value, default is UTF-8 * @throws java.io.CharConversionException */ public static void decode(final DataChunk originalURI, final DataChunk targetDecodedURI, final boolean isSlashAllowed, final Charset encoding) throws CharConversionException { // %xx decoding of the URL URLDecoder.decode(originalURI, targetDecodedURI, isSlashAllowed); if (!normalize(targetDecodedURI)) { throw new CharConversionException("Invalid URI character encoding"); } convertToChars(targetDecodedURI, encoding); }
/** * Configure the {@link WebappContext} * and {@link ServletConfigImpl} * * @throws javax.servlet.ServletException Error while configuring * {@link Servlet}. */ protected void configureServletEnv() throws ServletException { if (contextPath.length() > 0) { final CharChunk cc = new CharChunk(); char[] ch = contextPath.toCharArray(); cc.setChars(ch, 0, ch.length); HttpRequestURIDecoder.normalizeChars(cc); contextPath = cc.toString(); } if ("".equals(contextPath)) { contextPath = ""; } }
/** * Converts the normalized the HTTP request represented by the bytes inside * {@link DataChunk} to chars representation, using the passed encoding. * @param decodedURI - The bytes to decode * @param encoding the encoding value, default is UTF-8. * @throws java.io.CharConversionException */ public static void convertToChars(final DataChunk decodedURI, Charset encoding) throws CharConversionException { if (encoding == null) { encoding = UTF8_CHARSET; } decodedURI.toChars(encoding); // Check that the URI is still normalized if (!checkNormalize(decodedURI.getCharChunk())) { throw new CharConversionException("Invalid URI character encoding"); } }
if (c[pos] == '/') { while ((pos + 1 < end) && (c[pos + 1] == '/')) { copyChars(c, pos, pos + 1, end - pos - 1); end--; break; copyChars(c, start + index, start + index + 2, end - start - index - 2); end = end - 2; copyChars(c, start + index2, start + index + 3, end - start - index - 3); end = end + index2 - index - 3;
/** * Normalize URI. * <p> * This method normalizes "\", "//", "/./" and "/../". This method will * return false when trying to go above the root, or if the URI contains * a null byte. * * @param dataChunk URI to be normalized * @return <tt>true</tt> if normalization was successful, or <tt>false</tt> otherwise */ public static boolean normalize(final DataChunk dataChunk) { switch (dataChunk.getType()) { case Bytes: return normalizeBytes(dataChunk.getByteChunk()); case Buffer: return normalizeBuffer(dataChunk.getBufferChunk()); case String: try { dataChunk.toChars(null); } catch (CharConversionException unexpected) { // should never occur throw new IllegalStateException("Unexpected exception", unexpected); } // pass to Chars case case Chars: return normalizeChars(dataChunk.getCharChunk()); default: throw new NullPointerException(); } }
/** * Decode the HTTP request represented by the bytes inside {@link MessageBytes} * using an {@link UDecoder}, using the specified encoding, using the specified * [@link B2CConverter} to decode the request. * @param decodedURI - The bytes to decode * @param urlDecoder - The urlDecoder to use to decode. * @param encoding the encoding value, default is UTF-8. * @param b2cConverter the Bytes to Char Converter. * @throws java.lang.Exception */ public static void decode(final MessageBytes decodedURI, final UDecoder urlDecoder, String encoding, final B2CConverter b2cConverter) throws Exception { // %xx decoding of the URL urlDecoder.convert(decodedURI, false); if (!normalize(decodedURI)) { throw new IOException("Invalid URI character encoding"); } if (encoding == null) { encoding = "utf-8"; } convertURI(decodedURI, encoding, b2cConverter); // Check that the URI is still normalized if (!checkNormalize(decodedURI.getCharChunk())) { throw new IOException("Invalid URI character encoding"); } }
/** * Normalize URI. * <p> * This method normalizes "\", "//", "/./" and "/../". This method will * return false when trying to go above the root, or if the URI contains * a null byte. * * @param uriMB URI to be normalized * @return <tt>true</tt> if normalization was successful, or <tt>false</tt> otherwise */ public static boolean normalize(MessageBytes uriMB) { int type = uriMB.getType(); if (type == MessageBytes.T_CHARS) { return normalizeChars(uriMB.getCharChunk()); } else { return normalizeBytes(uriMB.getByteChunk()); } }
/** * Decode the HTTP request represented by the bytes inside {@link DataChunk}. * @param originalURI - The bytes to decode * @param targetDecodedURI the target {@link DataChunk} URI will be decoded to * @param isSlashAllowed is '/' an allowable character * @param encoding the encoding value, default is UTF-8 * @throws java.io.CharConversionException */ public static void decode(final DataChunk originalURI, final DataChunk targetDecodedURI, final boolean isSlashAllowed, final Charset encoding) throws CharConversionException { // %xx decoding of the URL URLDecoder.decode(originalURI, targetDecodedURI, isSlashAllowed); if (!normalize(targetDecodedURI)) { throw new CharConversionException("Invalid URI character encoding"); } convertToChars(targetDecodedURI, encoding); }
/** * Configure the {@link WebappContext} * and {@link ServletConfigImpl} * * @throws javax.servlet.ServletException Error while configuring * {@link Servlet}. */ protected void configureServletEnv() throws ServletException { if (contextPath.length() > 0) { final CharChunk cc = new CharChunk(); char[] ch = contextPath.toCharArray(); cc.setChars(ch, 0, ch.length); HttpRequestURIDecoder.normalizeChars(cc); contextPath = cc.toString(); } if ("".equals(contextPath)) { contextPath = ""; } }
/** * Converts the normalized the HTTP request represented by the bytes inside * {@link DataChunk} to chars representation, using the passed encoding. * @param decodedURI - The bytes to decode * @param encoding the encoding value, default is UTF-8. * @throws java.io.CharConversionException */ public static void convertToChars(final DataChunk decodedURI, Charset encoding) throws CharConversionException { if (encoding == null) { encoding = UTF8_CHARSET; } decodedURI.toChars(encoding); // Check that the URI is still normalized if (!checkNormalize(decodedURI.getCharChunk())) { throw new CharConversionException("Invalid URI character encoding"); } }
if (c[pos] == '/') { while ((pos + 1 < end) && (c[pos + 1] == '/')) { copyChars(c, pos, pos + 1, end - pos - 1); end--; break; copyChars(c, start + index, start + index + 2, end - start - index - 2); end = end - 2; copyChars(c, start + index2, start + index + 3, end - start - index - 3); end = end + index2 - index - 3;
/** * Normalize URI. * <p> * This method normalizes "\", "//", "/./" and "/../". This method will * return false when trying to go above the root, or if the URI contains * a null byte. * * @param dataChunk URI to be normalized * @return <tt>true</tt> if normalization was successful, or <tt>false</tt> otherwise */ public static boolean normalize(final DataChunk dataChunk) { switch (dataChunk.getType()) { case Bytes: return normalizeBytes(dataChunk.getByteChunk()); case Buffer: return normalizeBuffer(dataChunk.getBufferChunk()); case String: try { dataChunk.toChars(null); } catch (CharConversionException unexpected) { // should never occur throw new IllegalStateException("Unexpected exception", unexpected); } // pass to Chars case case Chars: return normalizeChars(dataChunk.getCharChunk()); default: throw new NullPointerException(); } }
/** * Decode the HTTP request represented by the bytes inside {@link MessageBytes} * using an {@link UDecoder}, using the specified encoding, using the specified * [@link B2CConverter} to decode the request. * @param decodedURI - The bytes to decode * @param urlDecoder - The urlDecoder to use to decode. * @param encoding the encoding value, default is UTF-8. * @param b2cConverter the Bytes to Char Converter. * @throws java.lang.Exception */ public static void decode(final MessageBytes decodedURI, final UDecoder urlDecoder, String encoding, final B2CConverter b2cConverter) throws Exception { // %xx decoding of the URL urlDecoder.convert(decodedURI, false); if (!normalize(decodedURI)) { throw new IOException("Invalid URI character encoding"); } if (encoding == null) { encoding = "utf-8"; } convertURI(decodedURI, encoding, b2cConverter); // Check that the URI is still normalized if (!checkNormalize(decodedURI.getCharChunk())) { throw new IOException("Invalid URI character encoding"); } }
/** * Normalize URI. * <p> * This method normalizes "\", "//", "/./" and "/../". This method will * return false when trying to go above the root, or if the URI contains * a null byte. * * @param uriMB URI to be normalized * @return <tt>true</tt> if normalization was successful, or <tt>false</tt> otherwise */ public static boolean normalize(MessageBytes uriMB) { int type = uriMB.getType(); if (type == MessageBytes.T_CHARS) { return normalizeChars(uriMB.getCharChunk()); } else { return normalizeBytes(uriMB.getByteChunk()); } }
/** * Decode the HTTP request represented by the bytes inside {@link DataChunk}. * @param originalURI - The bytes to decode * @param targetDecodedURI the target {@link DataChunk} URI will be decoded to * @param isSlashAllowed is '/' an allowable character * @param encoding the encoding value, default is UTF-8 * @throws java.io.CharConversionException */ public static void decode(final DataChunk originalURI, final DataChunk targetDecodedURI, final boolean isSlashAllowed, final Charset encoding) throws CharConversionException { // %xx decoding of the URL URLDecoder.decode(originalURI, targetDecodedURI, isSlashAllowed); if (!normalize(targetDecodedURI)) { throw new CharConversionException("Invalid URI character encoding"); } convertToChars(targetDecodedURI, encoding); }
/** * Decode the http request represented by the bytes inside {@link MessageBytes} * using an {@link UDecoder}. * @param decodedURI - The bytes to decode * @param urlDecoder - The urlDecoder to use to decode. * @throws java.lang.Exception */ public static void decode(final MessageBytes decodedURI, final UDecoder urlDecoder) throws Exception { decode(decodedURI, urlDecoder, null, null); }