Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo de-duplication of request parameters #839

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/main/java/org/htmlunit/WebRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
* @author Lai Quang Duong
* @author Kristof Neirynck
*/
public class WebRequest implements Serializable {

Check failure on line 58 in src/main/java/org/htmlunit/WebRequest.java

View workflow job for this annotation

GitHub Actions / PMD

[PMD] reported by reviewdog 🐶 Too many fields Raw Output: {"locations":[{"physicalLocation":{"artifactLocation":{"uri":"file:///home/runner/work/htmlunit/htmlunit/src/main/java/org/htmlunit/WebRequest.java"},"region":{"endColumn":2,"endLine":707,"startColumn":49,"startLine":58}}}],"message":{"text":"Too many fields"},"ruleId":"TooManyFields","ruleIndex":0}

public enum HttpHint {
/** Force to include the charset. */
Expand Down Expand Up @@ -413,14 +413,9 @@
return pairs;
}

final Set<String> keys = new HashSet<>();

final List<NameValuePair> resultingPairs = new ArrayList<>();
for (final NameValuePair pair : pairs) {
if (!keys.contains(pair.getName())) {
resultingPairs.add(pair.normalized());
keys.add(pair.getName());
}
resultingPairs.add(pair.normalized());
}

return resultingPairs;
Expand Down
40 changes: 26 additions & 14 deletions src/test/java/org/htmlunit/WebRequest2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

Expand All @@ -41,6 +41,8 @@
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;

import static java.util.stream.Collectors.toList;

/**
* Tests for {@link WebRequest#getParameters()}.
* This method is used by Spring test to shortcut the
Expand Down Expand Up @@ -226,12 +228,20 @@
final List<NameValuePair> parameters = request.getParameters();
assertEquals(expectedParameters.size(), parameters.size());

final Iterator<NameValuePair> expectedIter = expectedParameters.iterator();
for (final NameValuePair nameValuePair : parameters) {
final NameValuePair expectedNameValuePair = expectedIter.next();

assertEquals(expectedNameValuePair.getName(), nameValuePair.getName());
assertEquals(expectedNameValuePair.getValue(), nameValuePair.getValue());
final List<String> expectedNames = expectedParameters.stream().map(NameValuePair::getName).distinct().collect(toList());

Check failure on line 231 in src/test/java/org/htmlunit/WebRequest2Test.java

View workflow job for this annotation

GitHub Actions / CheckStyle

[checkstyle] reported by reviewdog 🐶 Line is longer than 120 characters (found 128). Raw Output: /home/runner/work/htmlunit/htmlunit/src/test/java/org/htmlunit/WebRequest2Test.java:231:0: error: Line is longer than 120 characters (found 128). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
final List<String> names = parameters.stream().map(NameValuePair::getName).distinct().collect(toList());
assertEquals("Parameter names should match", expectedNames, names);

for (final String name : expectedNames) {
final List<String> expectedValues = expectedParameters.stream()
.filter(pair -> name.equals(pair.getName()))
.map(NameValuePair::getValue)
.collect(toList());
final List<String> values = parameters.stream()
.filter(pair -> name.equals(pair.getName()))
.map(NameValuePair::getValue)
.collect(toList());
assertEquals("Parameter values for parameter with name '" + name + "' should match", expectedValues, values);

Check failure on line 244 in src/test/java/org/htmlunit/WebRequest2Test.java

View workflow job for this annotation

GitHub Actions / CheckStyle

[checkstyle] reported by reviewdog 🐶 Line is longer than 120 characters (found 121). Raw Output: /home/runner/work/htmlunit/htmlunit/src/test/java/org/htmlunit/WebRequest2Test.java:244:0: error: Line is longer than 120 characters (found 121). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
}
}

Expand Down Expand Up @@ -319,13 +329,15 @@
private static void bounce(final Writer writer,
final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
writer.write("Parameters: \n");
for (final String key : req.getParameterMap().keySet()) {
final String val = req.getParameter(key);
if (val == null) {
writer.write(" '" + key + "': '-null-'\n");
}
else {
writer.write(" '" + key + "': '" + val + "'\n");
for (final String name : Collections.list(req.getParameterNames())) {
final String[] values = req.getParameterValues(name);
if (values == null) {
// highly unlikely
writer.write(" '" + name + "': '-null-'\n");
} else {

Check failure on line 337 in src/test/java/org/htmlunit/WebRequest2Test.java

View workflow job for this annotation

GitHub Actions / CheckStyle

[checkstyle] reported by reviewdog 🐶 '}' at column 17 should be alone on a line. Raw Output: /home/runner/work/htmlunit/htmlunit/src/test/java/org/htmlunit/WebRequest2Test.java:337:17: error: '}' at column 17 should be alone on a line. (com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck)
for (String value : values) {

Check failure on line 338 in src/test/java/org/htmlunit/WebRequest2Test.java

View workflow job for this annotation

GitHub Actions / CheckStyle

[checkstyle] reported by reviewdog 🐶 Variable 'value' should be declared final. Raw Output: /home/runner/work/htmlunit/htmlunit/src/test/java/org/htmlunit/WebRequest2Test.java:338:33: error: Variable 'value' should be declared final. (com.puppycrawl.tools.checkstyle.checks.coding.FinalLocalVariableCheck)
writer.write(" '" + name + "': '" + value + "'\n");
}
}
}
}
Expand Down
Loading