Skip to content
Permalink
Browse files

Fixes for code review

  • Loading branch information...
dminkovsky committed Sep 30, 2017
1 parent 78977d5 commit c24a4d47912055f38fa16a5a969ec92859e0d06f
@@ -16,13 +16,7 @@
package io.netty.handler.codec.http.multipart;

import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.HttpConstants;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaderValues;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.handler.codec.http.QueryStringDecoder;
import io.netty.handler.codec.http.*;
import io.netty.handler.codec.http.multipart.HttpPostBodyUtil.SeekAheadOptimize;
import io.netty.handler.codec.http.multipart.HttpPostBodyUtil.TransferEncodingMechanism;
import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.EndOfDataDecoderException;
@@ -40,9 +34,11 @@
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.regex.Pattern;

import static io.netty.buffer.Unpooled.*;
import static io.netty.util.internal.ObjectUtil.*;
import static io.netty.buffer.Unpooled.buffer;
import static io.netty.util.internal.ObjectUtil.checkNotNull;
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;

/**
* This decoder will decode Body and can handle POST BODY.
@@ -795,33 +791,27 @@ private InterfaceHttpData findMultipartDisposition() {
}
}

private static final Pattern DOUBLE_SINGLE_QUOTE = Pattern.compile("''");
private static final String FILENAME_ENCODED = HttpHeaderValues.FILENAME.toString() + '*';

private Attribute getContentDispositionAttribute(String... values) {
Attribute attribute;
String name = cleanString(values[0]);
String value = values[1];

boolean shouldDecode = false;
int last = name.length() - 1;
if (name.charAt(last) == '*') {
shouldDecode = true;
name = name.substring(0, last);
}

// See http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html
if (HttpHeaderValues.FILENAME.contentEquals(name)) {
// filename value is quoted string so strip them
if (!shouldDecode) {
value = value.substring(1, value.length() - 1);
} else {
String[] split = value.split("''", 2);
value = QueryStringDecoder.decodeComponent(split[1], Charset.forName(split[0]));
}
value = value.substring(1, value.length() - 1);
} else if (FILENAME_ENCODED.equals(name)) {
// filename value is encoded. See https://tools.ietf.org/html/rfc5987
name = name.substring(0, name.length() - 1);
String[] split = DOUBLE_SINGLE_QUOTE.split(value, 2);
value = QueryStringDecoder.decodeComponent(split[1], Charset.forName(split[0]));
} else {
// otherwise we need to clean the value
value = cleanString(value);
}
attribute = factory.createAttribute(request, name, value);
return attribute;
return factory.createAttribute(request, name, value);
}

/**

0 comments on commit c24a4d4

Please sign in to comment.
You can’t perform that action at this time.