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

Adding Test Case for Additional Encoding Scenarios #2556

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 30 additions & 2 deletions core/src/test/java/feign/template/UriUtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 The Feign Authors
* Copyright 2012-2024 The Feign Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -14,9 +14,15 @@
package feign.template;


import feign.Param;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.nio.charset.StandardCharsets;
import java.util.stream.Stream;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;

class UriUtilsTest {

Expand All @@ -41,4 +47,26 @@ void pctEncodeWithReservedCharacters() {
String encoded = UriUtils.encode(withReserved, UTF_8, true);
assertThat(encoded).isEqualTo("/api/user@host:port#section[a-z]/data");
}

@ParameterizedTest
@MethodSource("provideValuesToEncode")
void testVariousEncodingScenarios(String input, String expected) {
assertThat(UriUtils.encode(input, UTF_8)).isEqualTo(expected);
}

private static Stream<Arguments> provideValuesToEncode() {
return Stream.of(
Arguments.of("foo", "foo"),
Arguments.of("foo bar", "foo%20bar"),
Arguments.of("foo%20bar", "foo%20bar"),
Arguments.of("foo%2520bar", "foo%2520bar"),
Arguments.of("foo&bar", "foo%26bar"),
Arguments.of("foo& bar", "foo%26%20bar"),
Arguments.of("foo = bar", "foo%20%3D%20bar"),
Arguments.of("foo ", "foo%20%20%20"),
Arguments.of("foo/bar", "foo%2Fbar"),
Arguments.of("foo!\"/$%?& *( ) _%20^¨ >`:É. ',. é ;`^ ¸< nasty stuff here!",
"foo%21%22%2F%24%25%3F%26%20%20%20%2A%28%20%29%20%20_%2520%5E%C2%A8%20%20%3E%60%3A%C3%89.%20%20%20%27%2C.%20%20%C3%A9%20%3B%60%5E%20%C2%B8%3C%20nasty%20stuff%20here%21"));

}
}
Loading