Skip to content

Commit

Permalink
Merge pull request #1441 from baranowb/UNDERTOW-1875_2
Browse files Browse the repository at this point in the history
[UNDERTOW-1875] - add system property to allow ID less matrix parameters
  • Loading branch information
fl4via authored Mar 25, 2023
2 parents af53274 + 0128007 commit c91fe12
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public abstract class HttpRequestParser {
private final String charset;
private final int maxCachedHeaderSize;
private final boolean allowUnescapedCharactersInUrl;
private final boolean allowIDLessMatrixParams;

private static final boolean[] ALLOWED_TARGET_CHARACTER = new boolean[256];

Expand Down Expand Up @@ -216,6 +217,7 @@ public HttpRequestParser(OptionMap options) {
charset = options.get(UndertowOptions.URL_CHARSET, StandardCharsets.UTF_8.name());
maxCachedHeaderSize = options.get(UndertowOptions.MAX_CACHED_HEADER_SIZE, UndertowOptions.DEFAULT_MAX_CACHED_HEADER_SIZE);
this.allowUnescapedCharactersInUrl = options.get(UndertowOptions.ALLOW_UNESCAPED_CHARACTERS_IN_URL, false);
this.allowIDLessMatrixParams = Boolean.parseBoolean(System.getProperty(ID_LESS_MATRIX_PARAMS_PROPERTY));
}

public static final HttpRequestParser instance(final OptionMap options) {
Expand Down Expand Up @@ -642,7 +644,7 @@ final void handlePathParameters(ByteBuffer buffer, ParseState state, HttpServerE
if (decode && (next == '+' || next == '%' || next > 127)) {
urlDecodeRequired = true;
}
if (next == '=' && param == null) {
if ((next == '=' || (next == ',' && this.allowIDLessMatrixParams)) && param == null) {
param = decode(stringBuilder.substring(pos), urlDecodeRequired, state, true, true);
urlDecodeRequired = false;
pos = stringBuilder.length() + 1;
Expand All @@ -668,11 +670,11 @@ final void handlePathParameters(ByteBuffer buffer, ParseState state, HttpServerE
state.nextQueryParam = param;
}

private void handleParsedParam(String previouslyParsedParam, String parsedParam, HttpServerExchange exchange, boolean urlDecodeRequired, ParseState state) throws BadRequestException {
if (previouslyParsedParam == null) {
exchange.addPathParam(decode(parsedParam, urlDecodeRequired, state, true, true), "");
private void handleParsedParam(String paramName, String parameterValue, HttpServerExchange exchange, boolean urlDecodeRequired, ParseState state) throws BadRequestException {
if (paramName == null) {
exchange.addPathParam(decode(parameterValue, urlDecodeRequired, state, true, true), "");
} else { // path param already parsed so parse and add the value
exchange.addPathParam(previouslyParsedParam, decode(parsedParam, urlDecodeRequired, state, true, true));
exchange.addPathParam(paramName, decode(parameterValue, urlDecodeRequired, state, true, true));
}
}

Expand Down

0 comments on commit c91fe12

Please sign in to comment.