Skip to content

Commit

Permalink
Fix URLDecodeProcessor random test failure (#5328) (#5340)
Browse files Browse the repository at this point in the history
The randomly-generated input for this test may contain non-URL-safe
characters (such as `%`) so it needs to be URL encoded as well.

Signed-off-by: Andrew Ross <andrross@amazon.com>

Signed-off-by: Andrew Ross <andrross@amazon.com>
(cherry picked from commit 152f3f4)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

Signed-off-by: Andrew Ross <andrross@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent d74d992 commit 4233454
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

package org.opensearch.ingest.common;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Map;

/**
Expand All @@ -48,11 +48,7 @@ public final class URLDecodeProcessor extends AbstractStringProcessor<String> {
}

public static String apply(String value) {
try {
return URLDecoder.decode(value, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException("Could not URL-decode value.", e);
}
return URLDecoder.decode(value, StandardCharsets.UTF_8);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@

package org.opensearch.ingest.common;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

public class URLDecodeProcessorTests extends AbstractStringProcessorTestCase<String> {
@Override
protected String modifyInput(String input) {
return "Hello%20G%C3%BCnter" + input;
return "Hello%20G%C3%BCnter" + urlEncode(input);
}

@Override
Expand All @@ -48,10 +49,10 @@ protected AbstractStringProcessor<String> newProcessor(String field, boolean ign

@Override
protected String expectedResult(String input) {
try {
return "Hello Günter" + URLDecoder.decode(input, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException("invalid");
}
return "Hello Günter" + URLDecoder.decode(urlEncode(input), StandardCharsets.UTF_8);
}

private static String urlEncode(String s) {
return URLEncoder.encode(s, StandardCharsets.UTF_8);
}
}

0 comments on commit 4233454

Please sign in to comment.