Skip to content

Commit 34a2b8c

Browse files
authored
Fix expression pattern compilation on android (#2136)
* Fix expression pattern compilation on android * Add test cases * Add license header * Reformat
1 parent 01e5503 commit 34a2b8c

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

core/src/main/java/feign/template/Expressions.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ public final class Expressions {
3939
*
4040
* <p>This is not a complete implementation of the rfc
4141
*
42-
* <p><a href="https://www.rfc-editor.org/rfc/rfc6570#section-2.2>RFC 6570 Expressions</a>
42+
* <p><a href="https://www.rfc-editor.org/rfc/rfc6570#section-2.2">RFC 6570 Expressions</a>
4343
*/
44-
private static final Pattern EXPRESSION_PATTERN =
45-
Pattern.compile("^(\\{([+#./;?&=,!@|]?)(.+)})$");
44+
static final Pattern EXPRESSION_PATTERN = Pattern.compile("^(\\{([+#./;?&=,!@|]?)(.+)\\})$");
4645

4746
// Partially From:
4847
// https://stackoverflow.com/questions/29494608/regex-for-uri-templates-rfc-6570-wanted -- I
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2012-2023 The Feign Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
package feign.template;
15+
16+
import static org.assertj.core.api.Assertions.assertThat;
17+
18+
import java.util.Collections;
19+
import org.junit.jupiter.api.Test;
20+
21+
public class ExpressionsTest {
22+
23+
@Test
24+
public void simpleExpression() {
25+
Expression expression = Expressions.create("{foo}");
26+
assertThat(expression).isNotNull();
27+
String expanded = expression.expand(Collections.singletonMap("foo", "bar"), false);
28+
assertThat(expanded).isEqualToIgnoringCase("foo=bar");
29+
}
30+
31+
@Test
32+
public void androidCompatibility() {
33+
// To match close brace on Android, it must be escaped due to the simpler ICU regex engine
34+
String pattern = Expressions.EXPRESSION_PATTERN.pattern();
35+
assertThat(pattern.contains("}")).isEqualTo(pattern.contains("\\}"));
36+
}
37+
}

0 commit comments

Comments
 (0)