Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ protected String withQueryWithParams(final String query, final List<Param> query
@Override
protected String withQueryWithoutParams(final String query) {
// encode query
StringBuilder sb = StringBuilderPool.DEFAULT.stringBuilder();
encodeAndAppendQuery(sb, query);
return sb.toString();
return Utf8UrlEncoder.encodeQuery(query);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public static String encodePath(String input) {
return sb == null ? input : sb.toString();
}

static String encodeQuery(String input) {
StringBuilder sb = lazyAppendEncoded(null, input, BUILT_QUERY_UNTOUCHED_CHARS, false);
return sb == null ? input : sb.toString();
}

public static StringBuilder encodeAndAppendQuery(StringBuilder sb, String query) {
return appendEncoded(sb, query, BUILT_QUERY_UNTOUCHED_CHARS, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import io.github.artsok.RepeatedIfExceptionsTest;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;

public class Utf8UrlEncoderTest {

Expand All @@ -28,6 +30,22 @@ public void testBasics() {
assertEquals("a%2Bb", Utf8UrlEncoder.encodeQueryElement("a+b"));
}

@RepeatedIfExceptionsTest(repeats = 5)
public void encodeQueryReusesInputWhenNothingNeedsEscaping() {
String query = "a=1&b=/two?c%20d";

assertSame(query, Utf8UrlEncoder.encodeQuery(query));
}

@RepeatedIfExceptionsTest(repeats = 5)
public void encodeQueryEscapesWhenNeeded() {
String query = "a=one two";
String encoded = Utf8UrlEncoder.encodeQuery(query);

assertNotSame(query, encoded);
assertEquals("a=one%20two", encoded);
}

@RepeatedIfExceptionsTest(repeats = 5)
public void testPercentageEncoding() {
assertEquals("foobar", Utf8UrlEncoder.percentEncodeQueryElement("foobar"));
Expand Down
Loading